|
Boost Users : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2006-02-02 02:18:48
Hi Matt,
> To further complicate the matter thread1 can't call notify_all again
> until it has been signaled to run (via a different condition variable)
> which is signaled by thread2.
>
> Does this make sense?
> Here's some pseudo code for what I'm doing.
> Thread2() //Master thread.
> {
> while(1)
> {
> scoped_lock l(mutex1);
> condition1.wait(l)
This is wrong. Your code should be written like this:
bool worker_thread_finished_working = false;
....
scoped_lock l(mutex1);
while(!worker_thread_finished_working)
condition1.wait(l);
That way, if worker thread has finished working before you enter wait, you
simply won't enter the loop and won't call condition1.wait. Call to
'notify_all' on condition should be considered as meaning "something in the
world has changed", and after waking from 'wait' you should reevaluate
necessary variables to decide if the wait is done or not. Using
'notify_all' in any other way is risky.
Some further notes can be found at:
http://vladimir_prus.blogspot.com/2005/07/spurious-wakeups.html
- Volodya
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