Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-09-20 07:38:58


Pavel Syomin wrote:
> Hi,
>
> I'm porting custom library from UNIX to Windows and found that some
> piece of code work correctly on UNIX and some time segfaulting on
> Windows. I think, that problem is on boost::condition::timed_wait()
> function. To be sure I write small test:

[...]

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.


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