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, class Predicate>
18 // wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time,
21 #include <condition_variable>
27 #include "make_test_thread.h"
28 #include "test_macros.h"
34 explicit Pred(int& i
) : i_(i
) {}
36 bool operator()() {return i_
!= 0;}
39 std::condition_variable_any cv
;
41 typedef std::timed_mutex L0
;
42 typedef std::unique_lock
<L0
> L1
;
50 bool expect_result
= false;
54 typedef std::chrono::system_clock Clock
;
55 typedef std::chrono::milliseconds milliseconds
;
60 Clock::time_point t0
= Clock::now();
61 bool result
= cv
.wait_for(lk
, milliseconds(250), Pred(test2
));
62 assert(result
== expect_result
);
63 Clock::time_point t1
= Clock::now();
66 assert(t1
- t0
< milliseconds(250));
71 assert(t1
- t0
- milliseconds(250) < milliseconds(50));
82 std::thread t
= support::make_test_thread(f
);
95 expect_result
= false;
97 std::thread t
= support::make_test_thread(f
);