PR libstdc++/55917 do not handle exceptions in std::thread

PR libstdc++/55917
	* src/c++11/thread.cc (execute_native_thread_routine): Remove
	try-block so that exceptions propagate out of the thread and terminate
	is called by the exception-handling runtime.
	(execute_native_thread_routine_compat): Likewise.
	* testsuite/30_threads/thread/cons/terminate.cc: New.

From-SVN: r249130
This commit is contained in:
Jonathan Wakely 2017-06-12 17:37:28 +01:00 committed by Jonathan Wakely
parent 196ed8eae5
commit 754d67d5ba
3 changed files with 59 additions and 28 deletions

View file

@ -1,3 +1,12 @@
2017-06-12 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/55917
* src/c++11/thread.cc (execute_native_thread_routine): Remove
try-block so that exceptions propagate out of the thread and terminate
is called by the exception-handling runtime.
(execute_native_thread_routine_compat): Likewise.
* testsuite/30_threads/thread/cons/terminate.cc: New.
2017-06-09 Jonathan Wakely <jwakely@redhat.com>
* doc/xml/manual/intro.xml: Document LWG 2802, 2873 and 2942 changes.

View file

@ -77,20 +77,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
execute_native_thread_routine(void* __p)
{
thread::_State_ptr __t{ static_cast<thread::_State*>(__p) };
__try
{
__t->_M_run();
}
__catch(const __cxxabiv1::__forced_unwind&)
{
__throw_exception_again;
}
__catch(...)
{
std::terminate();
}
__t->_M_run();
return nullptr;
}
@ -104,20 +91,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
// the thread state to a local object, breaking the reference cycle
// created in thread::_M_start_thread.
__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;
}
#endif

View file

@ -0,0 +1,48 @@
// Copyright (C) 2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do run { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-rtems* *-*-darwin* powerpc-ibm-aix* } }
// { dg-options "-pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* powerpc-ibm-aix* } }
// { dg-require-effective-target c++11 }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
#include <thread>
#include <exception>
#include <cstdlib>
void handle_terminate()
{
std::_Exit(0);
}
void f() { throw 1; }
void
test01()
{
std::set_terminate(handle_terminate);
std::thread t(f);
t.join();
std::abort();
}
int
main()
{
test01();
}