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
12 // <condition_variable>
14 // class condition_variable_any;
16 // template <class Lock, class Rep, class Period>
18 // wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time);
20 #include <condition_variable>
26 #include "make_test_thread.h"
27 #include "test_macros.h"
29 std::condition_variable_any cv
;
31 typedef std::timed_mutex L0
;
32 typedef std::unique_lock
<L0
> L1
;
39 bool expect_timeout
= false;
43 typedef std::chrono::system_clock Clock
;
44 typedef std::chrono::milliseconds milliseconds
;
49 Clock::time_point t0
= Clock::now();
50 Clock::time_point wait_end
= t0
+ milliseconds(250);
53 d
= wait_end
- Clock::now();
54 if (d
<= milliseconds(0)) break;
55 } while (test2
== 0 && cv
.wait_for(lk
, d
) == std::cv_status::no_timeout
);
56 Clock::time_point t1
= Clock::now();
59 assert(t1
- t0
< milliseconds(250));
64 assert(t1
- t0
- milliseconds(250) < milliseconds(50));
73 std::thread t
= support::make_test_thread(f
);
85 expect_timeout
= true;
88 std::thread t
= support::make_test_thread(f
);