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 <cassert> |
20 | #include <semaphore> |
21 | #include <thread> |
22 | |
23 | #include "make_test_thread.h" |
24 | #include "test_macros.h" |
25 | |
26 | int main(int, char**) |
27 | { |
28 | std::counting_semaphore<> s(1); |
29 | |
30 | assert(s.try_acquire()); |
31 | assert(!s.try_acquire()); |
32 | s.release(); |
33 | assert(s.try_acquire()); |
34 | assert(!s.try_acquire()); |
35 | s.release(2); |
36 | std::thread t = support::make_test_thread([&](){ |
37 | assert(s.try_acquire()); |
38 | }); |
39 | t.join(); |
40 | assert(s.try_acquire()); |
41 | assert(!s.try_acquire()); |
42 | |
43 | return 0; |
44 | } |
45 | |