multithreading - Using pthread in simple C++ OpenCV project -


i trying use pthread in opencv project. intially trying open 2 different images using 2 different threads. on windows7 + vs2010 + pthreads-win32 lib, program runs well.

but on debian jessei machine (opencv 2.4.1), same code, although compiles well, execution crashes following error.

[xcb] unknown request in queue while dequeuing [xcb] multi-threaded client , xinitthreads has not been called [xcb] aborting, sorry that. pthreadtest: ../../src/xcb_io.c:179: dequeue_pending_request: assertion `!xcb_xlib_unknown_req_in_deq' failed. aborted 

interestingly when 1 thread created [for (i=0; i<1; i++)], runs fine, , image displayed.

i have spent 1.5 days trying solve it, no luck. know, doing wrong ?

here code:

#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <cstdio> #include <iostream> #include <pthread.h>  using namespace cv; using namespace std;  struct thread_data {     bool isbig;     string filename; };   void *processimg(void *args) {     struct thread_data *data = (struct thread_data *) args;     const char * inputimgwinname = data->isbig ? "big img" : "small img";      cv::mat imginput = imread(data->filename, 1);      cv::namedwindow(inputimgwinname, cv::window_autosize);     cv::imshow(inputimgwinname, imginput);      cv::waitkey();     pthread_exit(null);     //return null; }   int main( int argc, char** argv ) {     struct thread_data data[2];      data[0].isbig = true;     data[0].filename = "img1.png";      data[1].isbig = false;     data[1].filename = "img2.png";      pthread_t threads[2];     pthread_attr_t attr;     void *status;      // initialize , set thread joinable     pthread_attr_init(&attr);     pthread_attr_setdetachstate(&attr, pthread_create_joinable);      // create threads      int rc;     (int i=0; i<2; i++) {         rc = pthread_create(&threads[i], &attr, processimg, (void *)&(data[i]));         if (rc) {             cout << "error: unable create thread";             return -1;         }     }      // free attribute , wait other threads     pthread_attr_destroy(&attr);     (int i=0; i<2; i++) {         rc = pthread_join(threads[i], &status);         if (rc){             cout << "error:unable join," << rc << endl;             exit(-1);         }         cout << "thread: "<< <<" exiting status: " << status << endl;     }      pthread_exit(null);         return 0; } 

ps: cannot using c++11 thread.h reason.

namedwindow, waitkey should go out of threads, you're interfering desktop/gui here


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -