]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2020-2022 Free Software Foundation, Inc. |
83a1beee TR |
2 | // |
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) | |
7 | // any later version. | |
8 | ||
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. | |
13 | ||
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/>. | |
17 | ||
a3313a22 | 18 | // { dg-options "-std=gnu++2a" } |
83a1beee | 19 | // { dg-do run { target c++2a } } |
83a1beee | 20 | // { dg-require-gthreads "" } |
a3313a22 | 21 | // { dg-additional-options "-pthread" { target pthread } } |
71dc5ae5 | 22 | // { dg-add-options libatomic } |
a3313a22 | 23 | |
83a1beee TR |
24 | #include <latch> |
25 | #include <atomic> | |
26 | #include <thread> | |
27 | #include <testsuite_hooks.h> | |
28 | ||
29 | void | |
30 | test01() | |
31 | { | |
32 | std::latch l(3); | |
33 | ||
34 | VERIFY( !l.try_wait() ); | |
35 | ||
36 | auto fn = [&] | |
37 | { | |
38 | l.count_down(); | |
39 | }; | |
40 | ||
41 | std::thread t0(fn); | |
42 | std::thread t1(fn); | |
43 | ||
44 | l.arrive_and_wait(); | |
45 | t0.join(); | |
46 | t1.join(); | |
47 | ||
48 | VERIFY( l.try_wait() ); | |
49 | } | |
50 | ||
51 | void | |
52 | test02() | |
53 | { | |
54 | std::latch l(3); | |
55 | std::thread t([&] | |
56 | { | |
57 | l.count_down(); | |
58 | }); | |
59 | ||
60 | l.arrive_and_wait(2); | |
61 | t.join(); | |
62 | VERIFY( l.try_wait() ); | |
63 | } | |
64 | ||
65 | int main() | |
66 | { | |
67 | test01(); | |
68 | test02(); | |
69 | return 0; | |
70 | } |