pthread_cond_broadcast()

Peter Slacik Peter.Slacik@tatramed.sk
Tue Jun 29 04:35:00 GMT 1999


Lorin Hochstein wrote:

> [....]
> I tried to test this by writing a smaller program which just does this
> (attached to this e-mail). However, this smaller program seems to have
> even bigger problems, the threads never respond to the broadcast, and I
> have no clue why (it works just fine in Linux)! Could anybody offer any
> assistance?

First, you are locking mutex1 in one thread - main(), and unlocks it in thread
which did not lock it - thread1(), thread2().

Second, you uses mutex1 for pthread_cond_wait() call (without locking it first).

Third, it is advisable to call pthread_cond_signal() / pthread_cond_broadcast()
with the associated mutex locked, and pthreads-win32 requests this.

And - each time check pthread_*() return values, even in the test code!

Hope this helps you

Peter Slacik





More information about the Pthreads-win32 mailing list