aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely.gcc@gmail.com>2012-08-25 23:01:40 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2012-08-26 00:01:40 +0100
commit277f43d2d0c4554d1c050a8c4e913cbf4d54cf4b (patch)
tree14a840fae3c8a2b3e7a91873a4133ad272af91d9 /libstdc++-v3
parent81ea3024cac22aa75bd589fa455b132895e1a82f (diff)
downloadgcc-277f43d2d0c4554d1c050a8c4e913cbf4d54cf4b.zip
gcc-277f43d2d0c4554d1c050a8c4e913cbf4d54cf4b.tar.gz
gcc-277f43d2d0c4554d1c050a8c4e913cbf4d54cf4b.tar.bz2
re PR libstdc++/54297 ([C++11] Segmentation fault with std::async and released shared state)
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. From-SVN: r190672
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog10
-rw-r--r--libstdc++-v3/include/std/future6
-rw-r--r--libstdc++-v3/src/c++11/future.cc3
-rw-r--r--libstdc++-v3/testsuite/30_threads/async/54297.cc50
4 files changed, 67 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 48ccb54..361abc5 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,15 @@
2012-08-25 Jonathan Wakely <jwakely.gcc@gmail.com>
+ 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.
+
+2012-08-25 Jonathan Wakely <jwakely.gcc@gmail.com>
+
PR libstdc++/54248
* include/bits/concept_check.h: Replace references to boost
namespace.
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index a8d7112..feae382 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -1427,10 +1427,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class __future_base::_Async_state_common : public __future_base::_State_base
{
protected:
-#ifdef _GLIBCXX_HAVE_TLS
+#if defined(_GLIBCXX_HAVE_TLS) && defined(_GLIBCXX_ABI_COMPAT_ASYNC)
~_Async_state_common();
#else
- ~_Async_state_common() { _M_join(); }
+ ~_Async_state_common() = default;
#endif
// Allow non-timed waiting functions to block until the thread completes,
@@ -1457,6 +1457,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} };
}
+ ~_Async_state_impl() { _M_join(); }
+
private:
typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
_Ptr_type _M_result;
diff --git a/libstdc++-v3/src/c++11/future.cc b/libstdc++-v3/src/c++11/future.cc
index 380c3a4..eaea393 100644
--- a/libstdc++-v3/src/c++11/future.cc
+++ b/libstdc++-v3/src/c++11/future.cc
@@ -22,6 +22,8 @@
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
+#define _GLIBCXX_ABI_COMPAT_ASYNC
+
#include <future>
namespace
@@ -86,6 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__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.
diff --git a/libstdc++-v3/testsuite/30_threads/async/54297.cc b/libstdc++-v3/testsuite/30_threads/async/54297.cc
new file mode 100644
index 0000000..1d4d0a4
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/async/54297.cc
@@ -0,0 +1,50 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* powerpc-ibm-aix* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2012 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/>.
+
+#include <chrono>
+#include <thread>
+#include <future>
+#include <set>
+#include <testsuite_hooks.h>
+
+struct Task;
+
+std::set<const Task*> dead_tasks;
+
+struct Task
+{
+ ~Task() { dead_tasks.insert(this); }
+
+ void operator()() const
+ {
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ VERIFY( dead_tasks.count(this) == 0 );
+ }
+};
+
+int main()
+{
+ std::async(std::launch::async, Task());
+}