]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/30_threads/async/69724.cc
1 // Copyright (C) 2019-2022 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
19 // { dg-options "-pthread" }
20 // { dg-require-effective-target c++11 }
21 // { dg-require-effective-target pthread }
22 // { dg-require-gthreads "" }
25 #include <testsuite_rvalref.h>
27 struct F
: __gnu_test::copycounter
31 F(const F
&) = default;
33 // Move constructor copies base class, to use counter:
34 F(F
&& f
) : copycounter(f
) { f
.valid
= false; }
36 void run() { VERIFY(this->valid
); }
42 std::future
<void> fut
;
45 fut
= std::async(&F::run
, F
{});
46 VERIFY( F::copycount
== 1 );
48 VERIFY( F::copycount
== 1 );
51 fut
= std::async(std::launch::async
, &F::run
, F
{});
52 VERIFY( F::copycount
== 1 );
54 VERIFY( F::copycount
== 1 );
57 fut
= std::async(std::launch::deferred
, &F::run
, F
{});
58 VERIFY( F::copycount
== 1 );
60 VERIFY( F::copycount
== 1 );
66 std::future
<void> fut
;
70 fut
= std::async(&F::run
, f
);
71 VERIFY( F::copycount
== 1 );
73 VERIFY( F::copycount
== 1 );
76 fut
= std::async(std::launch::async
, &F::run
, f
);
77 VERIFY( F::copycount
== 1 );
79 VERIFY( F::copycount
== 1 );
82 fut
= std::async(std::launch::deferred
, &F::run
, f
);
83 VERIFY( F::copycount
== 1 );
85 VERIFY( F::copycount
== 1 );
91 std::future
<void> fut
;
95 fut
= std::async(&F::run
, std::ref(f
));
96 VERIFY( F::copycount
== 0 );
98 VERIFY( F::copycount
== 0 );
101 fut
= std::async(std::launch::async
, &F::run
, std::ref(f
));
102 VERIFY( F::copycount
== 0 );
104 VERIFY( F::copycount
== 0 );
107 fut
= std::async(std::launch::deferred
, &F::run
, std::ref(f
));
108 VERIFY( F::copycount
== 0 );
110 VERIFY( F::copycount
== 0 );