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;
16 // template <class Rep, class Period, class Predicate>
18 // wait_for(unique_lock<mutex>& lock,
19 // const chrono::duration<Rep, Period>& rel_time,
22 #include <condition_variable>
28 #include "make_test_thread.h"
29 #include "test_macros.h"
35 explicit Pred(int& i
) : i_(i
) {}
37 bool operator()() {return i_
!= 0;}
40 std::condition_variable cv
;
50 typedef std::chrono::system_clock Clock
;
51 typedef std::chrono::milliseconds milliseconds
;
52 std::unique_lock
<std::mutex
> lk(mut
);
56 Clock::time_point t0
= Clock::now();
57 bool r
= cv
.wait_for(lk
, milliseconds(250), Pred(test2
));
58 ((void)r
); // Prevent unused warning
59 Clock::time_point t1
= Clock::now();
62 assert(t1
- t0
< milliseconds(250));
67 assert(t1
- t0
- milliseconds(250) < milliseconds(50));
76 std::unique_lock
<std::mutex
>lk(mut
);
77 std::thread t
= support::make_test_thread(f
);
90 std::unique_lock
<std::mutex
>lk(mut
);
91 std::thread t
= support::make_test_thread(f
);