1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: libcpp-has-no-threads
10 
11 // <condition_variable>
12 
13 // class condition_variable_any;
14 
15 // template <class Lock>
16 //   void wait(Lock& lock);
17 
18 #include <condition_variable>
19 #include <mutex>
20 #include <thread>
21 #include <cassert>
22 
23 std::condition_variable_any cv;
24 
25 typedef std::timed_mutex L0;
26 typedef std::unique_lock<L0> L1;
27 
28 L0 m0;
29 
30 int test1 = 0;
31 int test2 = 0;
32 
33 void f()
34 {
35     L1 lk(m0);
36     assert(test2 == 0);
37     test1 = 1;
38     cv.notify_one();
39     while (test2 == 0)
40         cv.wait(lk);
41     assert(test2 != 0);
42 }
43 
44 int main(int, char**)
45 {
46     L1 lk(m0);
47     std::thread t(f);
48     assert(test1 == 0);
49     while (test1 == 0)
50         cv.wait(lk);
51     assert(test1 != 0);
52     test2 = 1;
53     lk.unlock();
54     cv.notify_one();
55     t.join();
56 
57   return 0;
58 }
59