Boost C++ Libraries: Ticket #2100: thread fails to compile with -fno-exceptions https://svn.boost.org/trac10/ticket/2100 <p> The thread component fails to compile with GCC when -fno-exceptions is specified. The attached patch allows the libraries / tests shipped with boost 1.35.0 to compile. There didn't seem to be a better option to make g++ happy than to just #ifndef out the catch(...) block, as it would otherwise complain about the throw in the block. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2100 Trac 1.4.3 anonymous Thu, 10 Jul 2008 04:41:08 GMT attachment set https://svn.boost.org/trac10/ticket/2100 https://svn.boost.org/trac10/ticket/2100 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_thread_no_exceptions.diff</span> </li> </ul> Ticket Jonathan Wakely <jwakely.boost@…> Fri, 05 Jun 2009 15:20:24 GMT milestone changed https://svn.boost.org/trac10/ticket/2100#comment:1 https://svn.boost.org/trac10/ticket/2100#comment:1 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.40.0</span> </li> </ul> <p> I had a look at your patch, most of it looks fine, but you add std::exception as a base class of boost::thread_interrupted. That is a very bad idea, boost::thread_interrupted should not derive from any other type, so that normal exception-handling code will not interfere with interruption handling. </p> <p> Consider </p> <pre class="wiki">while (true) { try { lock_guard&lt;mutex&gt; lock(m_mutex); processQueue(m_queue); } catch (std::exception&amp; e) { std::cerr &lt;&lt; "Error processing queue: " &lt;&lt; e.what() &lt;&lt; '\n'; } } </pre><p> Currently this loop can be stopped by interrupting the thread, with your change it cannot. </p> Ticket Jonathan Wakely <jwakely.boost@…> Fri, 05 Jun 2009 15:27:16 GMT <link>https://svn.boost.org/trac10/ticket/2100#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:2</guid> <description> <p> oops, I meant to add a wait on a condition_variable so there's an interruption point... </p> <pre class="wiki">while (true) { try { unique_lock&lt;mutex&gt; lock(m_mutex); while (m_queue.empty()) m_cond.wait(lock); processQueue(m_queue); } catch (std::exception&amp; e) { std::cerr &lt;&lt; "Error processing queue: " &lt;&lt; e.what() &lt;&lt; '\n'; } } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 22 Nov 2009 19:15:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:3</guid> <description> <p> I think that Boost.Thread has not been designed to work without exception. What would be the behavior of the application if we remove just any throw statement? In order to achieve the reporter goal, we should need to add functions returning a return code. IMO this is out of the scope currently. Thus I propose to close the ticket. </p> </description> <category>Ticket</category> </item> <item> <author>Jonathan Wakely <jwakely.boost@…></author> <pubDate>Sun, 22 Nov 2009 19:38:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:4</guid> <description> <p> Did you look at the patch? Noone suggested changing the interface to use return codes. Are you familiar with boost::throw_exception? It allows the user to decide what should happen. One common option is to abort() instead of throwing. </p> </description> <category>Ticket</category> </item> <item> <author>Jonathan Wakely <jwakely.boost@…></author> <pubDate>Sun, 22 Nov 2009 19:41:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:5</guid> <description> <p> P.S. I don't object to closing the ticket, but I do object to closing it if it hasn't been properly reviewed and the OP's patch considered. Apologies if I misunderstood, but viboes' comment implied the patch hadn't been looked at </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 23 Nov 2009 14:18:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2100#comment:4" title="Comment 4">Jonathan Wakely &lt;jwakely.boost@…&gt;</a>: </p> <blockquote class="citation"> <p> Did you look at the patch? Noone suggested changing the interface to use return codes. Are you familiar with boost::throw_exception? It allows the user to decide what should happen. One common option is to abort() instead of throwing. </p> </blockquote> <p> I inspected the patch before posting and I know also boost::throw_exception. Do you mean that the application building with -fno-exceptions will be happy to abort instead of throwing an exception? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 23 Nov 2009 14:35:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2100#comment:6" title="Comment 6">viboes</a>: </p> <blockquote class="citation"> <p> I inspected the patch before posting and I know also boost::throw_exception. Do you mean that the application building with -fno-exceptions will be happy to abort instead of throwing an exception? </p> </blockquote> <p> Yes. In GCC's standard library using -fno-exceptions will turn any throw into an abort(), see <a class="ext-link" href="http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html#intro.using.exception.no"><span class="icon">​</span>http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html#intro.using.exception.no</a> </p> <p> So if a user is using GCC and compiling with -fno-exceptions then they *already* expect exceptions to cause the program to abort. The OP's patch does not suggest changing the API to use return codes, it just allows the user to decide what should happen when exceptions are disabled. Which is supported in other parts of Boost and seems like a reasonable request to me. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 24 Nov 2009 22:28:23 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/2100#comment:8 https://svn.boost.org/trac10/ticket/2100#comment:8 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author-anonymous">anonymous</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I've committed a change to trunk that uses boost::throw_exception in most cases. The only cases I haven't touched are where thread_interrupted is thrown at a cancellation point. Interruption relies on exceptions to work properly, and as Jonathan points out, thread_interruption should not be derived from std::exception (and so won't work with boost::throw_exception). </p> <p> I'm inclined to think that interruption should not be available with exceptions disabled, in which case this code can be masked with a #ifdef.h </p> Ticket nick@… Fri, 26 Feb 2010 18:30:37 GMT <link>https://svn.boost.org/trac10/ticket/2100#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:9</guid> <description> <p> I found not only do threads fail to compile with -fno-exceptions but also other utilities. The one I found was /boost/numeric/interval/checking.hpp in the operator() functions of the exception_create_empty and exception_invalid_number structs. </p> </description> <category>Ticket</category> </item> <item> <author>nstewart@…</author> <pubDate>Fri, 02 Apr 2010 21:13:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:10</guid> <description> <p> It seems that 1.42.0 doesn't have this change. I would much rather be using boost for mutex, etc than other pthread/win32 wrappers. But requiring exception support is a deal breaker. </p> </description> <category>Ticket</category> </item> <item> <author>nigels@…</author> <pubDate>Fri, 02 Apr 2010 21:13:40 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/2100#comment:11 https://svn.boost.org/trac10/ticket/2100#comment:11 <ul> <li><strong>cc</strong> <span class="trac-author">nigels@…</span> added </li> </ul> Ticket nigels@… Sat, 03 Apr 2010 18:38:08 GMT attachment set https://svn.boost.org/trac10/ticket/2100 https://svn.boost.org/trac10/ticket/2100 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_thread_pthread_thread_data_BOOST_NO_EXCEPTIONS.diff</span> </li> </ul> <p> pthread/thread_data.hpp patch for BOOST_NO_EXCEPTIONS </p> Ticket nigels@… Sat, 03 Apr 2010 18:53:11 GMT milestone changed https://svn.boost.org/trac10/ticket/2100#comment:12 https://svn.boost.org/trac10/ticket/2100#comment:12 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.40.0</span> → <span class="trac-field-new">Boost 1.43.0</span> </li> </ul> <p> Attached a small patch so that pthread/thread_data.hpp can compile with BOOST_NO_EXCEPTIONS defined for OSX Leopard (gcc 4.0.1). Interruption just doesn't seem relevant without exception handling support enabled. But that shouldn't hinder the use of other threading facilities. </p> <p> There is one other minor change I'd recommend for boost::thread and BOOST_NO_EXCEPTIONS harmony: boost/thread.hpp includes boost/thread/future.hpp which seems to require exception handling to be useful. I'll also attach a diff here for simply skipping that include if BOOST_NO_EXCEPTIONS is defined. </p> Ticket nigels@… Sat, 03 Apr 2010 18:58:18 GMT attachment set https://svn.boost.org/trac10/ticket/2100 https://svn.boost.org/trac10/ticket/2100 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_thread_hpp_BOOST_NO_EXCEPTIONS.diff</span> </li> </ul> <p> omit boost::thread::future from &lt;boost/thread.hpp&gt; if BOOST_NO_THREADS is defined </p> Ticket nigels@… Sat, 03 Apr 2010 19:31:06 GMT type changed https://svn.boost.org/trac10/ticket/2100#comment:13 https://svn.boost.org/trac10/ticket/2100#comment:13 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span> </li> </ul> Ticket nigels@… Mon, 05 Apr 2010 17:32:39 GMT attachment set https://svn.boost.org/trac10/ticket/2100 https://svn.boost.org/trac10/ticket/2100 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_thread_lib_src.diff</span> </li> </ul> <p> libs/pthread/src/thread.cpp patch for BOOST_NO_EXCEPTIONS </p> Ticket nigels@… Mon, 05 Apr 2010 17:34:39 GMT <link>https://svn.boost.org/trac10/ticket/2100#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:14</guid> <description> <p> One more patch for compiling the boost library in BOOST_NO_EXCEPTIONS mode. This is to ignore a try .. catch block and disable thread_interrupted throw. </p> </description> <category>Ticket</category> </item> <item> <author>nstewart@…</author> <pubDate>Fri, 07 May 2010 19:42:49 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2100 https://svn.boost.org/trac10/ticket/2100 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_thread_hpp_BOOST_NO_EXCEPTIONS_20100507.diff</span> </li> </ul> <p> Updated patch for boost/thread/... for pthread, win32 and future handling of BOOST_NO_EXCEPTIONS </p> Ticket nstewart@… Fri, 07 May 2010 19:46:48 GMT attachment set https://svn.boost.org/trac10/ticket/2100 https://svn.boost.org/trac10/ticket/2100 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_thread_lib_src_20100507.diff</span> </li> </ul> <p> Updated patch for boost/thread/... for pthread andwin32 handling of BOOST_NO_EXCEPTIONS, potential redefinition of WIN32_LEAN_AND_MEAN </p> Ticket nstewart@… Fri, 07 May 2010 19:48:21 GMT milestone changed https://svn.boost.org/trac10/ticket/2100#comment:15 https://svn.boost.org/trac10/ticket/2100#comment:15 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.43.0</span> → <span class="trac-field-new">Boost 1.44.0</span> </li> </ul> Ticket Anthony Williams Fri, 21 May 2010 17:12:34 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2100#comment:16 https://svn.boost.org/trac10/ticket/2100#comment:16 <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> Ticket nstewart@… Fri, 21 May 2010 17:51:03 GMT <link>https://svn.boost.org/trac10/ticket/2100#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:17</guid> <description> <p> Awesome to see this finally closed. Thanks! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 04 Mar 2011 18:03:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:18</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2100#comment:17" title="Comment 17">nstewart@…</a>: </p> <blockquote class="citation"> <p> Awesome to see this finally closed. Thanks! </p> </blockquote> <p> It looks like as of 1.46.0 (and svn on 3/4/2011) thread still fails to compile with -fno-exceptions. This patch does not look to have been entirely merged. For example, boost/thread/pthread/thread_data.hpp does not contain the "#ifndef BOOST_NO_EXCEPTIONS" guard around "throw thread_interrupted();". </p> </description> <category>Ticket</category> </item> <item> <author>nstewart@…</author> <pubDate>Sun, 06 Mar 2011 20:37:24 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2100 https://svn.boost.org/trac10/ticket/2100 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_thread_BOOST_NO_EXCEPTIONS_20110306.diff</span> </li> </ul> <p> Updated boost thread patch w.r.t trunk revision 69610 </p> Ticket anonymous Sun, 06 Mar 2011 20:39:50 GMT <link>https://svn.boost.org/trac10/ticket/2100#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:19</guid> <description> <p> Indeed, looking at boost/trunk, portions of the previous patch seem to be missing. Attached as ..._20110306.diff - ought to apply cleanly to svn. </p> <ul><li>Nigel </li></ul> </description> <category>Ticket</category> </item> <item> <author>nstewart@…</author> <pubDate>Sun, 06 Mar 2011 20:41:31 GMT</pubDate> <title>status, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/2100#comment:20 https://svn.boost.org/trac10/ticket/2100#comment:20 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">Boost 1.47.0</span> </li> </ul> <p> Reopened with suggested milestone of 1.47.0 </p> Ticket anonymous Thu, 14 Jul 2011 18:19:46 GMT <link>https://svn.boost.org/trac10/ticket/2100#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:21</guid> <description> <p> Since this missed 1.47.0 any chance it can make it into 1.48.0? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Thu, 14 Jul 2011 18:31:38 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/2100#comment:22 https://svn.boost.org/trac10/ticket/2100#comment:22 <ul> <li><strong>owner</strong> changed from <span class="trac-author-anonymous">anonymous</span> to <span class="trac-author">Anthony Williams</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket viboes Sat, 03 Dec 2011 11:19:12 GMT owner, status, milestone changed https://svn.boost.org/trac10/ticket/2100#comment:23 https://svn.boost.org/trac10/ticket/2100#comment:23 <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> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.47.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Tue, 06 Dec 2011 23:09:11 GMT type changed https://svn.boost.org/trac10/ticket/2100#comment:24 https://svn.boost.org/trac10/ticket/2100#comment:24 <ul> <li><strong>type</strong> <span class="trac-field-old">Patches</span> → <span class="trac-field-new">Feature Requests</span> </li> </ul> <p> This patch will need some documentation and tests to be complete. Moved to feature request until the missing pieces are available. </p> Ticket viboes Sun, 08 Jul 2012 16:18:02 GMT milestone changed https://svn.boost.org/trac10/ticket/2100#comment:25 https://svn.boost.org/trac10/ticket/2100#comment:25 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.51.0</span> </li> </ul> <p> Committed in trunk revision 79347. </p> Ticket nigels@… Sun, 08 Jul 2012 18:56:42 GMT <link>https://svn.boost.org/trac10/ticket/2100#comment:26 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:26</guid> <description> <p> For the most part, this all looks good in svn main trunk. However, there still appears to be an issue concerning thread_future.hpp: </p> <p> In file included from ../../../../../tools/Common/boost-1.50.0/boost/exception_ptr.hpp:9, </p> <blockquote> <p> from ../../../../../tools/Common/boost-1.50.0/boost/thread/future.hpp:18, from ../../../../../tools/Common/boost-1.50.0/boost/thread.hpp:24, from myheader.h:48: </p> </blockquote> <p> ../../../../../tools/Common/boost-1.50.0/boost/exception/detail/exception_ptr.hpp:17:2: error: #error This header requires exception handling to be enabled. </p> <p> My workaround for this is to move the #ifndef BOOST_NO_EXCEPTIONS to the entire scope of thread/future.hpp. </p> <p> And thanks for the long-awaited progress on this. :-) </p> <ul><li>Nigel </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 12 Aug 2012 20:04:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:27 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:27</guid> <description> <p> Committed in trunk revision 79365. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 12 Aug 2012 20:05:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:28 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:28</guid> <description> <p> Committed in trunk revision 79383. </p> </description> <category>Ticket</category> </item> <item> <author>nstewart@…</author> <pubDate>Wed, 15 Aug 2012 16:40:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:29 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:29</guid> <description> <p> Looks good. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 09 Sep 2012 08:59:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2100#comment:30 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2100#comment:30</guid> <description> <p> While Boost.Thread compiles now when BOOST_NO_EXCEPTIONS is defined, I have not yet checked disabling exceptions at the compiler side. </p> <p> In addition Boost.Thread depends on Boost.System and there some issue yet with this library. See <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/7149" title="#7149: Bugs: system failed to compile with BOOST_NO_EXCEPTIONS defined when ... (reopened)">#7149</a>: system failed to compile with BOOST_NO_EXCEPTIONS defined when -fno-exceptions is NOT used. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 09 Oct 2012 23:40:20 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2100#comment:31 https://svn.boost.org/trac10/ticket/2100#comment:31 <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> You will need to apply the patch attached to <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/7149" title="#7149: Bugs: system failed to compile with BOOST_NO_EXCEPTIONS defined when ... (reopened)">#7149</a>. </p> Ticket