Boost logo

Boost Users :

From: Alexander Terekhov (yg-boost-users_at_[hidden])
Date: 2003-05-09 07:34:11


Joshua Napoli wrote:
>
> Is there any way to wait for one of several condition objects to become
> ready? Is there some reason that this capability is omitted from the thread
> library?

;-) ...

"What you are asking for is like wanting to sleep in two or more beds
 at the same time. This, of course, is only possible if you are the
 president of the United States."

http://google.com/groups?selm=slrn7hiau9.1q3.kaz%40ashi.FootPrints.net
(Subject: Re: pthreads and waiting for MULTIPLE conditions)

Note that for "cominations" of predicates [which is what you probably
need], you'll have to use broadcast() [and never use signal()] unless
all of your possible waiters can "handle" each and every predicate that
you "combine". You should also protect all these predicates with *one
single mutex* because the use of different mutexes for concurrent
waiting on the same condition variable isn't allowed:

<http://tinyurl.com/bd0v>

----
Dave Butenhof wrote:
[...]
>   When a thread waits on a condition variable, having specified a
>   particular mutex to either the pthread_cond_timedwait() or
>   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. During
>   this time, the effect of an attempt by any thread to wait on that
>   condition variable using a different mutex is undefined. Once all
>   waiting threads have been unblocked (as by the
>   pthread_cond_broadcast() operation), the next wait operation on that
>   condition variable shall form a new dynamic binding with the mutex
>   specified by that wait operation. Even though the dynamic binding
>   between condition variable and mutex may be removed or replaced
>   between the time a thread is unblocked from a wait on the condition
>   variable and the time that it returns to the caller or begins
>   cancellation cleanup, the unblocked thread shall always re-acquire
>   the mutex specified in the condition wait operation call from which
>   it is returning.
----
regards,
alexander.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net