[flang][cuda] Do not register global constants (#118582)
[llvm-project.git] / libcxx / test / std / thread / thread.semaphore / try_acquire.pass.cpp
blobfb6fff3baf4c4f48f3dd72aa0b974dabc4ab554e
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, c++14, c++17
12 // XFAIL: availability-synchronization_library-missing
14 // <semaphore>
16 #include <cassert>
17 #include <semaphore>
18 #include <thread>
20 #include "make_test_thread.h"
21 #include "test_macros.h"
23 int main(int, char**)
25 std::counting_semaphore<> s(1);
27 assert(s.try_acquire());
28 assert(!s.try_acquire());
29 s.release();
30 assert(s.try_acquire());
31 assert(!s.try_acquire());
32 s.release(2);
33 std::thread t = support::make_test_thread([&](){
34 assert(s.try_acquire());
35 });
36 t.join();
37 assert(s.try_acquire());
38 assert(!s.try_acquire());
40 return 0;