I\'m looking for a way to wait for multiple condition variables. ie. something like:
boost::condition_variable cond1;
boost::condition_variable cond2;
void wa
I don't believe you can do anything like this with boost::thread. Perhaps because POSIX condition variables don't allow this type of construct. Of course, Windows has WaitForMultipleObjects as aJ posted, which could be a solution if you're willing to restrict your code to Windows synchronization primitives.
Another option would to use fewer condition variables: just have 1 condition variable that you fire when anything "interesting" happens. Then, any time you want to wait, you run a loop that checks to see if your particular situation of interest has come up, and if not, go back to waiting on the condition variable. You should be waiting on those condition variables in such a loop anyways, as condition variable waits are subject to spurious wakeups (from boost::thread docs, emphasis mine):
void wait(boost::unique_lock
...
Effects:
Atomically call lock.unlock()
and blocks the current thread. The thread will unblock when notified by a call to this->notify_one()
or this->notify_all()
, or spuriously. ...