[Boost-bugs] [Boost C++ Libraries] #4078: interrupt()ion of threads in timed_wait() of a condition variable has unexpected side effects

Subject: [Boost-bugs] [Boost C++ Libraries] #4078: interrupt()ion of threads in timed_wait() of a condition variable has unexpected side effects
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-04-08 17:54:51


#4078: interrupt()ion of threads in timed_wait() of a condition variable has
unexpected side effects
---------------------------------------------+------------------------------
 Reporter: Sebastian Kienzl <seb@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: thread
  Version: Boost 1.39.0 | Severity: Problem
 Keywords: |
---------------------------------------------+------------------------------
 If multiple threads are waiting on a condition variable with timed_wait()
 then interrupt()ing one them makes timed_wait() return {{{true}}} in
 another thread. Happens under Linux, not tested under Windows.

 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.

 {{{
 #include <boost/thread.hpp>
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/condition_variable.hpp>
 #include <iostream>

 using namespace std;
 using namespace boost;

 condition_variable cv;
 mutex mut;

 void test_thread( const char* name )
 {
         try {
                 mutex::scoped_lock lock( mut );
                 cout << name << " timed_wait: " <<
                         cv.timed_wait( lock, posix_time::time_duration( 0,
 20, 0 ) ) << endl;
         }
         catch( thread_interrupted& ) {
                 cout << name << " interrupted" << endl;
         }
 }


 int main()
 {
         thread thread1( test_thread, "1" );
         thread thread2( test_thread, "2" );


         sleep( 1 );
         cout << "intr 1" << endl;
         thread1.interrupt();
         sleep( 1 );
         cout << "intr 2" << endl;
         thread2.interrupt();
         sleep( 1 );

         thread1.join();
         thread2.join();

         return 0;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4078>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC