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
16 // template <class Rep, class Period>
17 // unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
24 #include "make_test_thread.h"
25 #include "test_macros.h"
29 typedef std::chrono::steady_clock Clock
;
30 typedef Clock::time_point time_point
;
31 typedef Clock::duration duration
;
32 typedef std::chrono::milliseconds ms
;
33 typedef std::chrono::nanoseconds ns
;
37 time_point t0
= Clock::now();
38 std::unique_lock
<std::timed_mutex
> lk(m
, ms(300));
39 assert(lk
.owns_lock() == true);
40 time_point t1
= Clock::now();
41 ns d
= t1
- t0
- ms(250);
42 assert(d
< ms(50)); // within 50ms
47 time_point t0
= Clock::now();
48 std::unique_lock
<std::timed_mutex
> lk(m
, ms(250));
49 assert(lk
.owns_lock() == false);
50 time_point t1
= Clock::now();
51 ns d
= t1
- t0
- ms(250);
52 assert(d
< ms(50)); // within 50ms
59 std::thread t
= support::make_test_thread(f1
);
60 std::this_thread::sleep_for(ms(250));
66 std::thread t
= support::make_test_thread(f2
);
67 std::this_thread::sleep_for(ms(300));