This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: pthread_cond_wait with multiple mutex variables


> -----Original Message-----
> From: Jonathan Nieder [mailto:jrnieder@gmail.com]
> 
> Bharath Ramesh wrote:
> >> From: Jonathan Nieder [mailto:jrnieder@gmail.com]
> 
> >> 	When a thread waits on a condition variable, having specified
> >> 	a particular mutex to either the pthread_cond_timedwait() or
> >> 	the pthread_cond_wait() operation, a dynamic binding is formed
> >> 	between that mutex and condition variable that remains in
> >> 	effect as long as at least one thread is blocked on the
> >> 	condition variable.
> [...]
> > One thing that I am still unclear about is that you mentioned
> > pthread_cond_broadcast uses __data.__mutex to decide what the woken
> threads
> > should wait on. This then should cause all the threads to wait on a
> > different mutex than what they really should wait on? Wouldn't this
> still
> > cause undefined behavior?
> 
> No, if all waiters specified the same mutex when calling
> pthread_cond_wait, it will be the right one.

In the benchmark I am working with, the waiters use the same condition variable but use different mutex variables (per work queue) in the condition wait. It seems like they might be unlocking a mutex which they really arenât holding when they return from the condition wait.

> 
> Ãngel's comment on semantics was much more helpful than mine.  The
> idea is that there is some state shared by several threads, protected
> from data races by a particular mutex.  When I call pthread_cond_wait,
> I am (1) waiting for that state to achieve a certain condition and (2)
> releasing the mutex to allow that to happen.

I did understand Angel's comment, and I have sent a note to the authors informing them about the bug in their benchmark.
 
Regards,

Bharath

Attachment: smime.p7s
Description: S/MIME cryptographic signature


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