ystarnaud

pthread problem

Jul 1st, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. int count = 0;
  2.  
  3. void thread_check()
  4. {
  5.     //if condition to trigger thread stuff isn't met, abort
  6.     if(!condition && count == 0)
  7.     {
  8.         return;
  9.     }
  10.  
  11.     //thread counter
  12.     count++;
  13.  
  14.     //all other threads waiting?
  15.     if(count >= thread_count)
  16.     {
  17.         //yes, do stuff...
  18.  
  19.         //reset counter before we leave
  20.         count = 0;
  21.  
  22.         //broadcast all threads to resume
  23.         mutex_lock(&mutex);         //<--- Hangs here
  24.         pthread_cond_broadcast(&cond);
  25.         mutex_unlock(&mutex);
  26.  
  27.     }
  28.     else
  29.     {
  30.         //make thread wait...
  31.         mutex_lock(&mutex);
  32.         pthread_cond_wait(&cond, &mutex);
  33.         mutex_unlock(&mutex);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment