Boost C++ Libraries: Ticket #5351: interrupt a future get boost::unknown_exception https://svn.boost.org/trac10/ticket/5351 <pre class="wiki">It may be a bug of the thread or future. in boost_1_46_0/doc/html/thread/synchronization.html it says: these Member functions: shared_future class template: Member function get() Member function wait() Member function timed_wait() and unique_future class template: Member function get() Member function wait() Member function timed_wait() Throws: ........ boost::thread_interrupted if the result associated with *this is not ready at the point of the call, and the [current] thread is interrupted. ............ but it throws boost::unknown_exception. and the [current] thread is interrupted. Should be the [working] thread is interrupted ? &gt; &gt; [Windows XP, VC++ 10, boost 1.46] &gt; &gt; When interrupt a future, the future.get() throw boost::unknown_exception, &gt; &gt; Not boost::thread_interrupted. &gt; &gt; &gt; &gt; Class boost::thread_interrupted should have a base class for &gt; &gt; current_exception_impl() to catch it ? or use BOOST_THROW_EXCEPTION to throw ? ////////// namespace boost { class thread_interrupted {}; } These function use [ throw thread_interrupted(); ] : this_thread ::interruption_point() // pthread / win32 this_thread::interruptible_wait() // win32 interruption_checker:: check_for_interruption()// pthread ///////////// // [Windows XP, VC++ 10, boost 1.46] #include &lt;boost/thread.hpp&gt; #include &lt;boost/date_time/posix_time/posix_time_types.hpp&gt; #include &lt;boost/thread/future.hpp&gt; using namespace boost::posix_time; using namespace boost; int foo() { this_thread::sleep(seconds(1000)); return 0; } int main(int argc, char** argv) { boost::packaged_task&lt;int&gt; pt(&amp;foo); boost::unique_future&lt;int&gt; fi = pt.get_future(); boost::thread task(std::move(pt)); // launch task on a thread task.interrupt(); try { int v = fi.get(); } catch (boost::exception&amp; exc) { std::cerr &lt;&lt; "ERROR: " &lt;&lt; boost::diagnostic_information(exc) &lt;&lt; std::endl; } } &gt; &gt; &gt; &gt; // unknown_exception////////////////// &gt; &gt; ERROR: Throw in function (unknown) &gt; &gt; Dynamic exception type: class boost::exception_detail::clone_impl&lt;class &gt; &gt; boost::unknown_exception&gt; &gt; &gt; std::exception::what: Unknown exception </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5351 Trac 1.4.3 viboes Sun, 04 Dec 2011 18:36:34 GMT owner, status, summary changed; cc set https://svn.boost.org/trac10/ticket/5351#comment:1 https://svn.boost.org/trac10/ticket/5351#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> <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> <li><strong>summary</strong> <span class="trac-field-old">[boost::thread] interrupt a future get boost::unknown_exception</span> → <span class="trac-field-new">interrupt a future get boost::unknown_exception</span> </li> </ul> Ticket viboes Sun, 11 Dec 2011 01:26:49 GMT attachment set https://svn.boost.org/trac10/ticket/5351 https://svn.boost.org/trac10/ticket/5351 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">5351.diff</span> </li> </ul> <p> a possible solution </p> Ticket viboes Sun, 11 Dec 2011 01:27:28 GMT <link>https://svn.boost.org/trac10/ticket/5351#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5351#comment:2</guid> <description> <p> I have reached to compile the example with some variants. </p> <p> It seems the problem comes from the fact that packaged_task catch every exception and store it to rethrow in the wait() function using boost::rethrow_exception. As thread_interrupted doesn't inherits from std/boost::exception the throw exception is unknown_exception. </p> <pre class="wiki"> if(rethrow &amp;&amp; exception) { boost::rethrow_exception(exception); } </pre><p> A solution could be to catch specifically thread_interrupted and store this fact. </p> <p> When wait is called, a test if the thread has been interrupted is done so that the exception thread_interrupted is thrown. The single problem is that the this new exception doesn't contains from where the initial thread_interrupted was thrown. </p> <p> See the attached patch for the complete solution. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 11 Dec 2011 01:29:55 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5351 https://svn.boost.org/trac10/ticket/5351 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_5351.cpp</span> </li> </ul> <p> The adapted test </p> Ticket viboes Mon, 19 Dec 2011 21:53:50 GMT <link>https://svn.boost.org/trac10/ticket/5351#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5351#comment:3</guid> <description> <p> There is also another patch that needs to be applied. See detail/move.hpp.diff file. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 19 Dec 2011 21:54:38 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5351 https://svn.boost.org/trac10/ticket/5351 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">detail_move.hpp.diff</span> </li> </ul> Ticket viboes Thu, 29 Dec 2011 14:14:34 GMT type changed https://svn.boost.org/trac10/ticket/5351#comment:4 https://svn.boost.org/trac10/ticket/5351#comment:4 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span> </li> </ul> Ticket viboes Sat, 07 Jan 2012 23:03:49 GMT milestone changed https://svn.boost.org/trac10/ticket/5351#comment:5 https://svn.boost.org/trac10/ticket/5351#comment:5 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.49.0</span> </li> </ul> Ticket viboes Tue, 17 Jan 2012 06:37:43 GMT <link>https://svn.boost.org/trac10/ticket/5351#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5351#comment:6</guid> <description> <p> Committed in trunk at revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/76543" title=" * [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to ...">[76543]</a>. However the issue seems to be also on Windows platforms. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 18 Jan 2012 02:09:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5351#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5351#comment:7</guid> <description> <p> catch (boost::thread_interrupted&amp; exc) </p> <p> if the caller of fi.get() is a boost::thread and is interrupted, get() will throw thread_interrupted. but the future is interrupted now, not the caller. so I recommend get() throw a new class boost::future_interrupted use BOOST_THROW_EXCEPTION. </p> <pre class="wiki">15 16 int main(int argc, char** argv) 17 { 18 boost::packaged_task&lt;int&gt; pt(&amp;foo); 19 boost::unique_future&lt;int&gt; fi = pt.get_future(); 20 boost::thread task(boost::move(pt)); // launch task on a thread 21 22 task.interrupt(); 23 24 try 25 { 26 int v = fi.get(); 27 } 28 catch (boost::thread_interrupted&amp; exc) 29 { 30 std::cout &lt;&lt; "OK: " &lt;&lt; std::endl; 31 return 0; 32 } 33 catch (boost::exception&amp; exc) 34 { 35 std::cout &lt;&lt; __LINE__ &lt;&lt; " ERROR: " &lt;&lt; boost::diagnostic_information(exc) &lt;&lt; std::endl; 36 return 1; 37 } 38 catch (...) 39 { 40 std::cout &lt;&lt; __LINE__ &lt;&lt; " ERROR: " &lt;&lt; std::endl; 41 return 2; 42 } 43 std::cout &lt;&lt; __LINE__ &lt;&lt; " ERROR: " &lt;&lt; std::endl; 44 return 3; 45 } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 28 May 2012 15:40:56 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/5351#comment:8 https://svn.boost.org/trac10/ticket/5351#comment:8 <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> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.49.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Committed in release branch at <a class="changeset" href="https://svn.boost.org/trac10/changeset/78543" title="Merged boost.thread from trunk">[78543]</a> </p> Ticket