43 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// <semaphore>13 14#include <semaphore>15#include <chrono>16#include <thread>17#include <type_traits>18 19#include "make_test_thread.h"20#include "test_macros.h"21 22static_assert(std::is_same<std::binary_semaphore, std::counting_semaphore<1>>::value, "");23 24int main(int, char**)25{26 std::binary_semaphore s(1);27 28 auto l = [&](){29 for(int i = 0; i < 1024; ++i) {30 s.acquire();31 std::this_thread::sleep_for(std::chrono::microseconds(1));32 s.release();33 }34 };35 36 std::thread t = support::make_test_thread(l);37 l();38 39 t.join();40 41 return 0;42}43