
20 Sep
2006
20 Sep
'06
12:13 p.m.
Peter Dimov wrote:
You are assuming that when condition::(timed_)wait returns the predicate (in your case m_counter != 0) is guaranteed to be true. This is not correct. condition::wait is allowed to return at any time (this is known as a "spurious wakeup".) You need to use a while loop.
while( m_counter == 0 ) { if( !m_condition.timed_wait( lock, time ) ) return; // timeout }
assert( m_counter != 0 ); --m_counter;
I'm almost 100% certain that this was in the documentation once, but I can't find it now. Maybe it somehow got lost in the transition to the new doc layout.
Thank you! This is solve my problems, but why there is nothing about spurious wakeup in boost documentation?...