
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.