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 11 12 // XFAIL: availability-synchronization_library-missing 13 14 // <semaphore> 15 16 #include <semaphore> 17 #include <chrono> 18 #include <thread> 19 #include <type_traits> 20 21 #include "make_test_thread.h" 22 #include "test_macros.h" 23 24 static_assert(std::is_same<std::binary_semaphore, std::counting_semaphore<1>>::value, ""); 25 26 int main(int, char**) 27 { 28 std::binary_semaphore s(1); 29 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(); 35 } 36 }; 37 38 std::thread t = support::make_test_thread(l); 39 l(); 40 41 t.join(); 42 43 return 0; 44 } 45