This is the mail archive of the
mailing list for the pthreas-win32 project.
- To: Peter Slacik <Peter.Slacik@tatramed.sk>
- Subject: Re: pthread_cond_broadcast()
- From: Lorin Hochstein <firstname.lastname@example.org>
- Date: Tue, 29 Jun 1999 09:09:15 -0400
- CC: pthreads mailing list <email@example.com>
- References: <3778FFC0.FFFDD5DD@xiphos.ca> <3778AF24.AC78BAC7@TatraMed.sk>
Thank you. Actually, the problem (in the original code, not in the test
code) was that the thread that called pthread_cond_broadcast() didn't
have the mutex... When I read the source code documentation for
pthread_cond_broadcast, I realized the error, and this fixed the
problem. You're supposed to do this with all pthread implementations
(not just pthreads-win32), but somehow Linux let me get away with it.
Peter Slacik wrote:
> 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