
October 29th, 2006, 10:19 PM
|
 |
Contributing User
|
|
Join Date: Mar 2002
Posts: 253

Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
|
|
|
Pthread_cond_wait
Hi,
I have a thread 'A' that tells other threads 'B' to start and then it waits for all other threads 'B' to finish.
static pthread_cond_t condStart = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutexStart = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t condFinish = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutexFinish = PTHREAD_MUTEX_INITIALIZER;
in thread 'A'
pthread_cond_broadcast(&condStart,&mutexStart);
while(finishedCount<threadCount)
{
pthread_cond_wait(&condFinish,&mutexFinish);
finishedCount++;
}
in thread 'B'
pthread_cond_wait(&condStart,&mutexStart);
...do work....
pthread_cond_signal(&condFinish);
Sometimes, even though threads 'B' signal condFinish, thread 'A' does not recieve it...
Anyone knows whats going on?
__________________
Thank you for any help.
|