]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/30_threads/thread/cons/9.cc
[ARM] Make gcc.target/arm/its.c more robust
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 30_threads / thread / cons / 9.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* *-*-solaris* powerpc-ibm-aix* } }
3// { dg-require-effective-target c++11 }
f3eb9681
BK
4// { dg-require-cstdint "" }
5// { dg-require-gthreads "" }
6
cbe34bb5 7// Copyright (C) 2009-2017 Free Software Foundation, Inc.
f3eb9681
BK
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
748086b7 12// Free Software Foundation; either version 3, or (at your option)
f3eb9681
BK
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
748086b7
JJ
21// with this library; see the file COPYING3. If not see
22// <http://www.gnu.org/licenses/>.
f3eb9681 23
f3eb9681
BK
24
25#include <thread>
26#include <system_error>
27#include <testsuite_hooks.h>
28
29int total = 0;
30
31// Functor has internal state.
32struct moveable
33{
34 int i;
35
36 moveable() = default;
37 ~moveable() = default;
38 moveable(const moveable& c) = delete;
39 moveable& operator=(const moveable&) = delete;
40
41 moveable(int j): i(j) { }
42 moveable(moveable&& m): i(m.i) { }
43
44 void operator()() const { total += i; }
45};
46
47// Two threads called by same functor type, different functor objects
48// that have different state. Make sure each thread calls the correct
49// functor.
50void test09()
51{
f3eb9681
BK
52 try
53 {
54 // first
55 moveable m1(60);
56 std::thread t1(std::move(m1));
57 t1.join();
58 VERIFY( total == 60 );
59
60 // second
61 moveable m2(600);
62 std::thread t2(std::move(m2));
63 t2.join();
64 VERIFY( total == 660 ); // Not 120...
65 }
66 catch (const std::system_error&)
67 {
68 VERIFY( false );
69 }
70 catch (...)
71 {
72 VERIFY( false );
73 }
74}
75
76int main()
77{
78 test09();
79 return 0;
80}