Boost C++ Libraries: Ticket #4078: interrupt()ion of threads in timed_wait() of a condition variable has unexpected side effects https://svn.boost.org/trac10/ticket/4078 <p> If multiple threads are waiting on a condition variable with timed_wait() then interrupt()ing one them makes timed_wait() return <code>true</code> in another thread. Happens under Linux, not tested under Windows. </p> <p> I haven't tested it with version later than 1.39.0 but couldn't find a ticket reporting that bug or any mention of it in the changelog. </p> <pre class="wiki">#include &lt;boost/thread.hpp&gt; #include &lt;boost/thread/mutex.hpp&gt; #include &lt;boost/thread/condition_variable.hpp&gt; #include &lt;iostream&gt; using namespace std; using namespace boost; condition_variable cv; mutex mut; void test_thread( const char* name ) { try { mutex::scoped_lock lock( mut ); cout &lt;&lt; name &lt;&lt; " timed_wait: " &lt;&lt; cv.timed_wait( lock, posix_time::time_duration( 0, 20, 0 ) ) &lt;&lt; endl; } catch( thread_interrupted&amp; ) { cout &lt;&lt; name &lt;&lt; " interrupted" &lt;&lt; endl; } } int main() { thread thread1( test_thread, "1" ); thread thread2( test_thread, "2" ); sleep( 1 ); cout &lt;&lt; "intr 1" &lt;&lt; endl; thread1.interrupt(); sleep( 1 ); cout &lt;&lt; "intr 2" &lt;&lt; endl; thread2.interrupt(); sleep( 1 ); thread1.join(); thread2.join(); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4078 Trac 1.4.3 Steven Watanabe Thu, 08 Apr 2010 19:45:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4078#comment:1 https://svn.boost.org/trac10/ticket/4078#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> This behavior is expected. Spurious wakeups are permitted for condition variables. This is one of the reasons why you usually need to wait in a loop. </p> Ticket anonymous Wed, 14 Apr 2010 09:57:37 GMT <link>https://svn.boost.org/trac10/ticket/4078#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4078#comment:2</guid> <description> <p> Thanks for the answer. With this explanation in mind, the documentation and the code-blocks in "Effects" make more sense. </p> <p> However, the only thing in the written documentation to suggest this behaviour are the words "or spuriously" for both wait() and timed_wait(). If you're aware of POSIX CV-semantics, it's understood. If you aren't (like I was), it's easy to miss this detail. Maybe it would be helpful to point this out more authoritatively. </p> </description> <category>Ticket</category> </item> </channel> </rss>