1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11
12 // XFAIL: availability-synchronization_library-missing
21 #include "make_test_thread.h"
22 #include "test_macros.h"
26 auto const start
= std::chrono::steady_clock::now();
28 std::counting_semaphore
<> s(0);
30 assert(!s
.try_acquire_until(start
+ std::chrono::milliseconds(250)));
31 assert(!s
.try_acquire_for(std::chrono::milliseconds(250)));
33 std::thread t
= support::make_test_thread([&](){
34 std::this_thread::sleep_for(std::chrono::milliseconds(250));
36 std::this_thread::sleep_for(std::chrono::milliseconds(250));
40 assert(s
.try_acquire_until(start
+ std::chrono::seconds(2)));
41 assert(s
.try_acquire_for(std::chrono::seconds(2)));
44 auto const end
= std::chrono::steady_clock::now();
45 assert(end
- start
< std::chrono::seconds(10));