This is the mail archive of the pthreads-win32@sourceware.cygnus.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: pthread_cond_broadcast()


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.

Lorin Hochstein

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]