Re: [Boost-bugs] [Boost C++ Libraries] #7238: this_thread::sleep_for() does not respond to interrupt()

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #7238: this_thread::sleep_for() does not respond to interrupt()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-08-16 21:07:14


#7238: this_thread::sleep_for() does not respond to interrupt()
-------------------------------+--------------------------------------------
  Reporter: CSB | Owner: anthonyw
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: thread
   Version: Boost 1.50.0 | Severity: Showstopper
Resolution: | Keywords: thread sleep_for interrupt
-------------------------------+--------------------------------------------

Comment (by Nick F):

 I am also observing the issue on Ubuntu 12.04. See the test reproducer
 below.

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

 using namespace boost;
 using namespace boost::chrono;

 void f()
 {
     try
     {
         std::cout << "Starting sleep in thread" << std::endl;
         while(true)
         {
             this_thread::sleep_for(seconds(60));
         }
     }
     catch(const thread_interrupted&)
     {
         std::cout << "Thread interrupted." << std::endl;
     }
 }

 int main(int argc, char** argv)
 {
     thread t(f);
     t.interrupt();
     t.join();
     std::cout << "Joined with thread." << std::endl;
     return 0;
 }
 }}}

 The problem seems to be due to the following. On platforms where
 BOOST_HAS_NANOSLEEP is defined, a nanosleep-based implementation is used
 for sleep_for (see thread/src/pthread/thread.cpp), which presumably does
 not allow the interruption mechanisms to work. Commenting out the
 BOOST_HAS_NANOSLEEP section in the above file and allowing the
 condition_variable based implementation to be used causes the above
 example to run as expected.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7238#comment:1>
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:10 UTC