1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // UNSUPPORTED: no-threads |
10 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
11 | |
12 | // XFAIL: availability-synchronization_library-missing |
13 | |
14 | // <barrier> |
15 | |
16 | #include <barrier> |
17 | #include <thread> |
18 | #include <cassert> |
19 | |
20 | #include "make_test_thread.h" |
21 | #include "test_macros.h" |
22 | |
23 | int main(int, char**) |
24 | { |
25 | int x = 0; |
26 | auto comp = [&]() noexcept { x += 1; }; |
27 | std::barrier<decltype(comp)> b(2, comp); |
28 | |
29 | std::thread t = support::make_test_thread([&](){ |
30 | for(int i = 0; i < 10; ++i) |
31 | b.arrive_and_wait(); |
32 | }); |
33 | |
34 | for(int i = 0; i < 10; ++i) |
35 | b.arrive_and_wait(); |
36 | |
37 | assert(x == 10); |
38 | t.join(); |
39 | return 0; |
40 | } |
41 |