Boost logo

Boost Users :

Subject: [Boost-users] [thread] Synchronisation Across Multiple Condition Variables
From: Alex Adranghi (mail_at_[hidden])
Date: 2008-10-05 12:52:47

Dear All,

I'd like to ask the floor what is the best way to wait on multiple
condition variables, with the first one causing the "aggregated wait" to
return with some distinguishable value.

I'm looking to achieve something akin to .NET's WaitHandle.WaitAny, or a
limited Occam ALT.
After a quick peak at the source, I believe this would be a non-trivial
change to the library.
A way around it involves sharing data and wrapping a condition, defining
notify() to take a boost:condition_variable. This would notify the
condition_variable argument* so that sole observers will be notified,
then setting an identifier to a member field, followed by notifying the
wrapped general condition itself.
The new aggregated wait() would first wait for a notification from the
wrapped condition, before retrieving the identifier written to the
object to return.
Problem is, I don't think this is particularly elegant. Another solution
is using threads to wait for each boost::condition_variable, but I don't
see this as practical due to obvious overhead.
*However this means for notify(), observers of the sole condition have
waking preference over observers of the aggregated condition, and there
is no way to know if any thread has been woken (in order to determine
whether to notify the wrapped boost::condition_variable).
Thanks for reading this, and answers on a postcard appreciated ;).
Best regards,
Alex Adranghi
mail: mail_at_[hidden]
pgp: 0x6770b73f

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at