[Bug libstdc++/55917] Impossible to find/debug unhandled exceptions in an std::thread

howard.hinnant at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri May 20 21:16:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55917

Howard Hinnant <howard.hinnant at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |howard.hinnant at gmail dot com

--- Comment #14 from Howard Hinnant <howard.hinnant at gmail dot com> ---
The main function is not wrapped in a try / catch and an unhandled exception on
the main thread still calls std::terminate() as required.

I believe that gcc already correctly implements the call to std::terminate()
for threads elsewhere, and with the same code that it does for main.  It is in
the function __cxa_throw, implemented by libsupc++.  Here is the specification:

http://mentorembedded.github.io/cxx-abi/abi-eh.html#cxx-throw

which says in part:

> __Unwind_RaiseException begins the process of stack unwinding, described in Section 2.5. In special cases, such as an inability to find a handler, _Unwind_RaiseException may return. In that case, __cxa_throw will call terminate, assuming that there was no handler for the exception.

And here is where it is implemented:

https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/eh_throw.cc#L87

As long as libsupc++ is being used on the platform, I think you are good to
remove the try/catch from execute_native_thread_routine.

Fwiw, this is what is done on libc++ / libc++abi (no try/catch at the top of
std::thread, and let __cxa_throw call terminate).  We get beautiful stack dumps
from threaded code over there. :-)


More information about the Gcc-bugs mailing list