Subj : Re: Help: Why is pthread_cond_broadcast not unblocking all threads To : comp.programming.threads From : Loic Domaigne Date : Sun Feb 13 2005 11:42 pm Hi Harry, > Hi: I am creating 3 threads and they all are waiting in on > pthread_cond_wait(). A seperate thread is sending a signal > pthread_cond_broadcast. However, only one thread comes out of the wait > instead of all of the thread coming out.. Please help. Thanks a whole > bunch First note that, normally, a predicate should be associated to a condition variable. That is, you are normally waiting for the predicate to become true as follows: pthread_mutex_lock (&mutex); while ( !predicate) { pthread_cond_wait (&condition, &mutex) } // here the mutex is locked again Whereas you should signal in a similar manner: pthread_mutex_lock (&mutex); predicate = true; pthread_mutex_unlock (&mutex); pthread_cond_broadcast (&condition); Now assuming that you just want to test the "wake-up" mechanism and do not mind about the predicate, your code becomes: void* WorkerThreads(void* ) { cout << "Starting to Wait[" << pthread_self() << "]" << endl; pthread_mutex_lock( &mutex ); pthread_cond_wait( &condition, &mutex ); pthread_mutex_unlock( &mutex ); cout << "Out of Wait[" << pthread_self() << "]" << endl; return NULL; } void* Broadcast(void* ) { sleep(7); pthread_cond_broadcast( &condition ); cout << "sent the broadcast signal" << endl; return NULL; } ( rest unchanged ) Hope this Help, Loic. .