diff --git a/src/demo.c b/src/demo.c index f261631d..a529bd38 100644 --- a/src/demo.c +++ b/src/demo.c @@ -156,8 +156,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int flag_exit = 0; - pthread_t fetch_thread; - pthread_t detect_thread; + custom_thread_t fetch_thread = NULL; + custom_thread_t detect_thread = NULL; fetch_in_thread(0); det_img = in_img; @@ -214,8 +214,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int int local_nboxes = nboxes; detection *local_dets = dets; - if (!benchmark) if (pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); - if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); + if (!benchmark) if (custom_create_thread(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); + if(custom_create_thread(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); //if (nms) do_nms_obj(local_dets, local_nboxes, l.classes, nms); // bad results if (nms) { @@ -285,9 +285,9 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int printf("\n cvWriteFrame \n"); } - pthread_join(detect_thread, 0); + custom_join(detect_thread, 0); if (!benchmark) { - pthread_join(fetch_thread, 0); + custom_join(fetch_thread, 0); free_image(det_s); } diff --git a/src/http_stream.cpp b/src/http_stream.cpp index c71a7f47..c8d4b583 100644 --- a/src/http_stream.cpp +++ b/src/http_stream.cpp @@ -682,6 +682,27 @@ void show_total_time() { std::cout << " Total: " << total_time * 1000 << " msec" << std::endl; } + +int custom_create_thread(custom_thread_t * tid, const custom_attr_t * attr, void *(*func) (void *), void *arg) +{ + *tid = (custom_thread_t *)new std::thread(func, arg); + if (tid) return 0; + else return -1; +} + +int custom_join(custom_thread_t thread, void **value_ptr) +{ + std::thread *ptr = (std::thread *)thread; + if (ptr) { + ptr->join(); + delete ptr; + return 0; + } + else printf(" Error: ptr of thread is NULL in custom_join() \n"); + + return -1; +} + #else // C++11 #include diff --git a/src/http_stream.h b/src/http_stream.h index 92765647..0aa63d65 100644 --- a/src/http_stream.h +++ b/src/http_stream.h @@ -18,6 +18,12 @@ int send_http_post_request(char *http_post_host, int server_port, const char *vi #endif // OPENCV +typedef void* custom_thread_t; +typedef void* custom_attr_t; + +int custom_create_thread(custom_thread_t * tid, const custom_attr_t * attr, void *(*func) (void *), void *arg); +int custom_join(custom_thread_t thread, void **value_ptr); + #ifdef __cplusplus } #endif