From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109480 invoked by alias); 12 Jun 2017 16:39:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 109456 invoked by uid 89); 12 Jun 2017 16:39:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=letting X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Jun 2017 16:39:07 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 226254E4D0; Mon, 12 Jun 2017 16:39:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 226254E4D0 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jwakely@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 226254E4D0 Received: from localhost (unknown [10.33.36.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA06180F63; Mon, 12 Jun 2017 16:39:10 +0000 (UTC) Date: Mon, 12 Jun 2017 16:39:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR libstdc++/55917 do not handle exceptions in std::thread Message-ID: <20170612163910.GA13462@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="jRHKVT23PllUwdXP" Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.8.0 (2017-02-23) X-SW-Source: 2017-06/txt/msg00814.txt.bz2 --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 556 Catching the exception and calling std::terminate() prevents a useful backtrace. Letting the runtime call terminate because of an unhandled exception gives a backtrace showing the site of the throw. 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. Tested powerpc64le-linux, committed to trunk. --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 3331 commit fb9352fda94d20ff6cfcc1370003716b7bd2c232 Author: Jonathan Wakely Date: Mon Jun 12 17:11:24 2017 +0100 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. diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc index 44a230a..4a94bdd 100644 --- a/libstdc++-v3/src/c++11/thread.cc +++ b/libstdc++-v3/src/c++11/thread.cc @@ -77,20 +77,7 @@ namespace std _GLIBCXX_VISIBILITY(default) execute_native_thread_routine(void* __p) { thread::_State_ptr __t{ static_cast(__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 diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/terminate.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/terminate.cc new file mode 100644 index 0000000..4b35b6c --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/terminate.cc @@ -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 +// . + +// { 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 +#include +#include + +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(); +} --jRHKVT23PllUwdXP--