39 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10// UNSUPPORTED: c++03, c++11, c++14, c++1711 12// <barrier>13 14#include <barrier>15#include <thread>16#include <cassert>17 18#include "make_test_thread.h"19#include "test_macros.h"20 21int main(int, char**)22{23 int x = 0;24 auto comp = [&]() noexcept { x += 1; };25 std::barrier<decltype(comp)> b(2, comp);26 27 std::thread t = support::make_test_thread([&](){28 for(int i = 0; i < 10; ++i)29 b.arrive_and_wait();30 });31 32 for(int i = 0; i < 10; ++i)33 b.arrive_and_wait();34 35 assert(x == 10);36 t.join();37 return 0;38}39