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>
18 // wait_for(unique_lock<mutex>& lock,
19 // const chrono::duration<Rep, Period>& rel_time);
21 #include <condition_variable>
27 #include "make_test_thread.h"
28 #include "test_macros.h"
30 std::condition_variable cv
;
36 bool expect_timeout
= false;
40 typedef std::chrono::system_clock Clock
;
41 typedef std::chrono::milliseconds milliseconds
;
42 std::unique_lock
<std::mutex
> lk(mut
);
46 Clock::time_point t0
= Clock::now();
47 Clock::time_point wait_end
= t0
+ milliseconds(250);
50 d
= wait_end
- Clock::now();
51 if (d
<= milliseconds(0)) break;
52 } while (test2
== 0 && cv
.wait_for(lk
, d
) == std::cv_status::no_timeout
);
53 Clock::time_point t1
= Clock::now();
56 assert(t1
- t0
< milliseconds(250));
61 assert(t1
- t0
- milliseconds(250) < milliseconds(50));
69 std::unique_lock
<std::mutex
> lk(mut
);
70 std::thread t
= support::make_test_thread(f
);
82 expect_timeout
= true;
84 std::unique_lock
<std::mutex
> lk(mut
);
85 std::thread t
= support::make_test_thread(f
);