]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/shared_ptr/atomic/3.cc
Simplify dg-options for tests using pthreads
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / shared_ptr / atomic / 3.cc
CommitLineData
37d13ae6 1// { dg-do run { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-rtems* *-*-darwin* powerpc-ibm-aix* } }
71c54f8e
JW
2// { dg-options "-pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* *-*-solaris* } }
3// { dg-require-effective-target c++11 }
be8de894
JW
4// { dg-require-cstdint "" }
5// { dg-require-gthreads "" }
6
818ab71a 7// Copyright (C) 2014-2016 Free Software Foundation, Inc.
be8de894
JW
8//
9// This file is part of the GNU ISO C++ Library. This library is free
10// software; you can redistribute it and/or modify it under the
11// terms of the GNU General Public License as published by the
12// Free Software Foundation; either version 3, or (at your option)
13// any later version.
14
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19
20// You should have received a copy of the GNU General Public License along
21// with this library; see the file COPYING3. If not see
22// <http://www.gnu.org/licenses/>.
23
24#include <thread>
25#include <memory>
26#include <testsuite_hooks.h>
27
28struct leaddock
29{
30 ~leaddock();
31};
32
33std::shared_ptr<leaddock> global;
34
35leaddock::~leaddock()
36{
37 // If this destructor is called "inside" an atomic operation on global it
38 // will deadlock, so this checks that the atomic_store is done atomically.
39 auto copy = std::atomic_load(&global);
40 VERIFY( !copy );
41}
42
43void f()
44{
45 std::atomic_store(&global, std::make_shared<leaddock>());
46 std::atomic_store(&global, {});
47}
48
49int main()
50{
51 std::thread{ f }.join();
52}