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

--- Comment #15 from Howard Hinnant <howard.hinnant at gmail dot com> ---
To help clarify my proposal, here is a patch:

diff --git a/libstdc++-v3/src/c++11/thread.cc
b/libstdc++-v3/src/c++11/thread.cc
index 906cafa..cfca178 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -79,19 +79,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
       thread::__shared_base_type __local;
       __local.swap(__t->_M_this_ptr);

-      __try
-       {
-         __t->_M_run();
-       }
-      __catch(const __cxxabiv1::__forced_unwind&)
-       {
-         __throw_exception_again;
-       }
-      __catch(...)
-       {
-         std::terminate();
-       }
-
+       __t->_M_run();
       return nullptr;
     }
   }

My colleague Miguel Portilla has tested this patch with the following code:

#include <thread>
#include <stdexcept>

void a(int i);
void b(int i);
void c(int i);

int
main()
{
    auto t = std::thread{a, 3};
    t.join();
}

void
a(int i)
{
    b(i-1);
}

void
b(int i)
{
    c(i-1);
}

void
c(int i)
{
    throw std::runtime_error("A good message");
}

And the stack dump looks like:

Thread 2 (Thread 0x7f090b47c740 (LWP 1865)):
#0  0x00007f090b0688ed in pthread_join (threadid=139676803389184,
thread_return=0x0) at pthread_join.c:90
#1  0x00007f090ad9c767 in __gthread_join (__value_ptr=0x0,
__threadid=<optimized out>)
    at
/home/mickey/gcc-5.4.0/build/x86_64-linux-gnu/libstdc++-v3/include/x86_64-linux-gnu/bits/gthr-default.h:668
#2  std::thread::join (this=0x7ffd1dae6430) at
../../../../../libstdc++-v3/src/c++11/thread.cc:96
#3  0x0000000000400f39 in main ()

Thread 1 (Thread 0x7f090a3fd700 (LWP 1866)):
#0  0x00007f090a433267 in __GI_raise (sig=sig@entry=6) at
../sysdeps/unix/sysv/linux/raise.c:55
#1  0x00007f090a434eca in __GI_abort () at abort.c:89
#2  0x00007f090ad747dd in __gnu_cxx::__verbose_terminate_handler ()
    at ../../../../libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x00007f090ad72866 in __cxxabiv1::__terminate (handler=<optimized out>)
    at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:47
#4  0x00007f090ad728b1 in std::terminate () at
../../../../libstdc++-v3/libsupc++/eh_terminate.cc:57
#5  0x00007f090ad72ac8 in __cxxabiv1::__cxa_throw (obj=0x7f0904000940, 
    tinfo=0x604360 <typeinfo for std::runtime_error@@GLIBCXX_3.4>, 
    dest=0x400ce0 <std::runtime_error::~runtime_error()@plt>) at
../../../../libstdc++-v3/libsupc++/eh_throw.cc:87
#6  0x0000000000400fdd in c(int) ()
#7  0x0000000000400fa0 in b(int) ()
#8  0x0000000000400f85 in a(int) ()
#9  0x0000000000402574 in void std::_Bind_simple<void
(*(int))(int)>::_M_invoke<0ul>(std::_Index_tuple<0ul>) ()
#10 0x0000000000402493 in std::_Bind_simple<void (*(int))(int)>::operator()()
()
#11 0x0000000000402432 in std::thread::_Impl<std::_Bind_simple<void
(*(int))(int)> >::_M_run() ()
#12 0x00007f090ad9c820 in std::execute_native_thread_routine (__p=<optimized
out>)
    at ../../../../../libstdc++-v3/src/c++11/thread.cc:82
#13 0x00007f090b0676aa in start_thread (arg=0x7f090a3fd700) at
pthread_create.c:333
#14 0x00007f090a504e9d in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Reply via email to