Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / thread / thread.semaphore / binary.pass.cpp
blob111a650b5ea39c4088d7c1ddb71d2cbcffc8508d
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
12 // XFAIL: availability-synchronization_library-missing
14 // <semaphore>
16 #include <semaphore>
17 #include <chrono>
18 #include <thread>
19 #include <type_traits>
21 #include "make_test_thread.h"
22 #include "test_macros.h"
24 static_assert(std::is_same<std::binary_semaphore, std::counting_semaphore<1>>::value, "");
26 int main(int, char**)
28 std::binary_semaphore s(1);
30 auto l = [&](){
31 for(int i = 0; i < 1024; ++i) {
32 s.acquire();
33 std::this_thread::sleep_for(std::chrono::microseconds(1));
34 s.release();
38 std::thread t = support::make_test_thread(l);
39 l();
41 t.join();
43 return 0;