Boost C++ Libraries: Ticket #7238: this_thread::sleep_for() does not respond to interrupt() https://svn.boost.org/trac10/ticket/7238 <p> Calling the interrupt() member of a thread has no effect when the thread calls this_thread::sleep_for(). The trivial program used to test this did exhibit the correct behaviour for this_thread::sleep_until() and this_thread::sleep(). </p> <p> Test run on CentOS 6.3 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7238 Trac 1.4.3 Nick F Thu, 16 Aug 2012 21:07:14 GMT <link>https://svn.boost.org/trac10/ticket/7238#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7238#comment:1</guid> <description> <p> I am also observing the issue on Ubuntu 12.04. See the test reproducer below. </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/thread.hpp&gt; using namespace boost; using namespace boost::chrono; void f() { try { std::cout &lt;&lt; "Starting sleep in thread" &lt;&lt; std::endl; while(true) { this_thread::sleep_for(seconds(60)); } } catch(const thread_interrupted&amp;) { std::cout &lt;&lt; "Thread interrupted." &lt;&lt; std::endl; } } int main(int argc, char** argv) { thread t(f); t.interrupt(); t.join(); std::cout &lt;&lt; "Joined with thread." &lt;&lt; std::endl; return 0; } </pre><p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 17 Aug 2012 14:37:51 GMT</pubDate> <title>severity changed https://svn.boost.org/trac10/ticket/7238#comment:2 https://svn.boost.org/trac10/ticket/7238#comment:2 <ul> <li><strong>severity</strong> <span class="trac-field-old">Showstopper</span> → <span class="trac-field-new">Problem</span> </li> </ul> <p> Thanks for catching this. </p> <p> I don't think this is a Showstopper as you can add a call to this_thread::interruption_point() together with the call to sleep_for, isn't it? </p> Ticket viboes Sat, 18 Aug 2012 08:17:03 GMT <link>https://svn.boost.org/trac10/ticket/7238#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7238#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7238#comment:2" title="Comment 2">viboes</a>: </p> <blockquote class="citation"> <p> Thanks for catching this. </p> <p> I don't think this is a Showstopper as you can add a call to this_thread::interruption_point() together with the call to sleep_for, isn't it? </p> </blockquote> <p> Forget the last comment. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 18 Aug 2012 09:27:26 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7238 https://svn.boost.org/trac10/ticket/7238 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">7238.patch</span> </li> </ul> <p> Please, could you try this patch? </p> Ticket viboes Sat, 18 Aug 2012 11:27:33 GMT milestone changed https://svn.boost.org/trac10/ticket/7238#comment:4 https://svn.boost.org/trac10/ticket/7238#comment:4 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.52.0</span> </li> </ul> <p> Committed in trunk revision 80076. </p> Ticket viboes Sat, 18 Aug 2012 11:30:56 GMT owner, status changed https://svn.boost.org/trac10/ticket/7238#comment:5 https://svn.boost.org/trac10/ticket/7238#comment:5 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sun, 09 Sep 2012 18:09:52 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7238#comment:6 https://svn.boost.org/trac10/ticket/7238#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Merged to release <a class="changeset" href="https://svn.boost.org/trac10/changeset/80450" title="Thread: merge from trunk: 1.52">[80450]</a>. </p> Ticket