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

source code of libcxx/test/std/thread/thread.semaphore/binary.pass.cpp