63 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// This is a regression test for https://llvm.org/PR47013.13 14// <semaphore>15 16#include <barrier>17#include <semaphore>18#include <thread>19#include <vector>20 21#include "make_test_thread.h"22 23static std::counting_semaphore<> s(0);24static std::barrier<> b(8 + 1);25 26void acquire() {27 for (int i = 0; i < 10'000; ++i) {28 s.acquire();29 b.arrive_and_wait();30 }31}32 33void release() {34 for (int i = 0; i < 10'000; ++i) {35 s.release(1);36 s.release(1);37 s.release(1);38 s.release(1);39 40 s.release(1);41 s.release(1);42 s.release(1);43 s.release(1);44 45 b.arrive_and_wait();46 }47}48 49int main(int, char**) {50 for (int run = 0; run < 20; ++run) {51 std::vector<std::thread> threads;52 for (int i = 0; i < 8; ++i)53 threads.push_back(support::make_test_thread(acquire));54 55 threads.push_back(support::make_test_thread(release));56 57 for (auto& thread : threads)58 thread.join();59 }60 61 return 0;62}63