From patchwork Sun Aug 26 14:00:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 180055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 983732C00D4 for ; Mon, 27 Aug 2012 00:00:20 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1346594421; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=c1ofuEaHgmcPvdTAn58ULR/jEzQ=; b=l51aM+5cmLvmkTN 3Zfwp0Rhb7jRqExjHtJvcEGhf0pAlViuyYl7A+yCYc8sr7FCzDAtKS2GZI/Stm5w 3jNoGaTi+3m5xRHhzesZ42DsoLG9FTrf4xROkfYQgSZTGyGSM8uuv0Zr2yXUrz/l kMLG6cvTzalZaje/NwwPmlOo6UJ4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=jl3cmqQu96LTFnfA9kASUNp/76kYLieOUvjV0wDZtIUYuZHSWtOJLQOtHqFjOn PJnPQZDXRWZNMl5dWAXWIMaIqUhZq33WCrUGqI5zSIILAzqhyrIF8IW62b/pARf9 nVJ2bc3YOwnQK6souk3qSqLk0aw7h/a9x/MeyQETSIuMM=; Received: (qmail 18902 invoked by alias); 26 Aug 2012 14:00:15 -0000 Received: (qmail 18878 invoked by uid 22791); 26 Aug 2012 14:00:14 -0000 X-SWARE-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, URIBL_BLACK X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 26 Aug 2012 14:00:01 +0000 Received: by iaky10 with SMTP id y10so6673595iak.20 for ; Sun, 26 Aug 2012 07:00:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.212.98 with SMTP id nj2mr7379479igc.35.1345989600358; Sun, 26 Aug 2012 07:00:00 -0700 (PDT) Received: by 10.42.49.81 with HTTP; Sun, 26 Aug 2012 07:00:00 -0700 (PDT) In-Reply-To: References: Date: Sun, 26 Aug 2012 15:00:00 +0100 Message-ID: Subject: Re: [v3] fix PR 54297 - segfaults with std::async From: Jonathan Wakely To: "libstdc++" , gcc-patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 26 August 2012 00:02, Jonathan Wakely wrote: > This fixes a stupid mistake I made where the functor and asynchronous > result can go out of scope before the async thread is joined. > > The _Async_state_common destructor still needs to be exported from the > library, which is what the macro hack is for. > > PR libstdc++/54297 > * include/std/future (~_Async_state_impl): Join thread before > derived class members are destroyed. > (~_Async_state_common): Only define non-trivial destructor when > included from future.cc for ABI compatibility reasons. > * src/c++11/future.cc (_GLIBCXX_ABI_COMPAT_ASYNC): Define. > * testsuite/30_threads/async/54297.cc: New. > > Tested x86_64-linux, committed to trunk and 4.7 I realised the compatibility symbols should be in one of the files used for that purpose, so this moves them to src/c++11/compatibility-thread-c++0x.cc PR libstdc++/54297 * src/c++11/future.cc (~_Async_state_common): Move to... * src/c++11/compatibility-thread-c++0x.cc (~_Async_state_common): Here. (_GLIBCXX_ABI_COMPAT_ASYNC): Rename to _GLIBCXX_ASYNC_ABI_COMPAT. * include/std/future (_GLIBCXX_ABI_COMPAT_ASYNC): Likewise. Tested x86_64-linux, committed to trunk and 4.7 commit 463ac67acbdada5a558dcad097e030a7479086c5 Author: Jonathan Wakely Date: Sun Aug 26 11:42:00 2012 +0100 PR libstdc++/54297 * src/c++11/future.cc (~_Async_state_common): Move to... * src/c++11/compatibility-thread-c++0x.cc (~_Async_state_common): Here. (_GLIBCXX_ABI_COMPAT_ASYNC): Rename to _GLIBCXX_ASYNC_ABI_COMPAT. * include/std/future (_GLIBCXX_ABI_COMPAT_ASYNC): Likewise. diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index feae382..9568192 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -1427,7 +1427,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __future_base::_Async_state_common : public __future_base::_State_base { protected: -#if defined(_GLIBCXX_HAVE_TLS) && defined(_GLIBCXX_ABI_COMPAT_ASYNC) +#ifdef _GLIBCXX_ASYNC_ABI_COMPAT ~_Async_state_common(); #else ~_Async_state_common() = default; diff --git a/libstdc++-v3/src/c++11/compatibility-thread-c++0x.cc b/libstdc++-v3/src/c++11/compatibility-thread-c++0x.cc index cc8761e..e5c7eec 100644 --- a/libstdc++-v3/src/c++11/compatibility-thread-c++0x.cc +++ b/libstdc++-v3/src/c++11/compatibility-thread-c++0x.cc @@ -22,11 +22,16 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . +#include +#if defined(_GLIBCXX_HAVE_TLS) && defined(PIC) +#define _GLIBCXX_ASYNC_ABI_COMPAT +#endif + #include #include #ifndef __GXX_EXPERIMENTAL_CXX0X__ -# error "compatibility-c++0x.cc must be compiled with -std=gnu++0x" +# error "compatibility-thread-c++0x.cc must be compiled with -std=gnu++0x" #endif #define _GLIBCXX_ASM_SYMVER(cur, old, version) \ @@ -70,3 +75,23 @@ _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx11try_to_lockE, _ZSt11try_to_lock, GLIBCXX_3.4. #endif #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 + + +// XXX GLIBCXX_ABI Deprecated +// gcc-4.7.0 +// export changes +#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ + && (ATOMIC_INT_LOCK_FREE > 1) +#if defined(_GLIBCXX_HAVE_TLS) && defined(PIC) +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + __future_base::_Async_state_common::~_Async_state_common() { _M_join(); } + + // Explicit instantiation due to -fno-implicit-instantiation. + template void call_once(once_flag&, void (thread::*&&)(), reference_wrapper&&); + template _Bind_simple_helper>::__type __bind_simple(void (thread::*&&)(), reference_wrapper&&); +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif +#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 diff --git a/libstdc++-v3/src/c++11/future.cc b/libstdc++-v3/src/c++11/future.cc index eaea393..0552537 100644 --- a/libstdc++-v3/src/c++11/future.cc +++ b/libstdc++-v3/src/c++11/future.cc @@ -22,8 +22,6 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . -#define _GLIBCXX_ABI_COMPAT_ASYNC - #include namespace @@ -86,15 +84,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __future_base::_Result_base::~_Result_base() = default; __future_base::_State_base::~_State_base() = default; - -#ifdef _GLIBCXX_HAVE_TLS - // Exported for compatibility with ABI version 3.4.17 - __future_base::_Async_state_common::~_Async_state_common() { _M_join(); } - - // Explicit instantiation due to -fno-implicit-instantiation. - template void call_once(once_flag&, void (thread::*&&)(), reference_wrapper&&); - template _Bind_simple_helper>::__type __bind_simple(void (thread::*&&)(), reference_wrapper&&); -#endif #endif _GLIBCXX_END_NAMESPACE_VERSION