Subj : Help: Why is pthread_cond_broadcast not unblocking all threads To : comp.programming.threads From : harryr2003 Date : Sat Feb 12 2005 10:48 am 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 Harry. The output from the following attached program is $ pgm Starting to Wait[4] Starting to Wait[5] Starting to Wait[6] sent the broadcast signal Out of Wait[4] A simple program that spins off 3 detached thread that waits for a signal. The other thread sends a signal. #include #include #include #include pthread_cond_t condition; pthread_mutex_t mutex; void DetachThreadAndRun(void * StartFunc_(void*), void * arg); using namespace std; 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_mutex_unlock( &mutex ); pthread_cond_broadcast( &condition ); cout << "sent the broadcast signal" << endl; return NULL; } // PROGRAM.. int main(int argc, char **argv) { pthread_mutex_init( &mutex, 0 ); pthread_cond_init( &condition, 0 ); for(int i=0; i < 3; i++) DetachThreadAndRun(WorkerThreads, (void *) NULL); DetachThreadAndRun(Broadcast, (void *) NULL); pause(); pthread_mutex_destroy( &mutex ); pthread_cond_destroy( &condition ); return 0; } void DetachThreadAndRun(void * StartFunc_(void*), void * arg) { pthread_t tid; pthread_attr_t attr; int n; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_create(&tid, &attr, StartFunc_, (void *) arg); pthread_attr_destroy(&attr); } .