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 #include "make_test_thread.h"
24 #include "test_macros.h"
25 
26 std::condition_variable_any cv;
27 
28 typedef std::timed_mutex L0;
29 typedef std::unique_lock<L0> L1;
30 
31 L0 m0;
32 
33 int test1 = 0;
34 int test2 = 0;
35 
f()36 void f()
37 {
38     L1 lk(m0);
39     assert(test2 == 0);
40     test1 = 1;
41     cv.notify_one();
42     while (test2 == 0)
43         cv.wait(lk);
44     assert(test2 != 0);
45 }
46 
main(int,char **)47 int main(int, char**)
48 {
49     L1 lk(m0);
50     std::thread t = support::make_test_thread(f);
51     assert(test1 == 0);
52     while (test1 == 0)
53         cv.wait(lk);
54     assert(test1 != 0);
55     test2 = 1;
56     lk.unlock();
57     cv.notify_one();
58     t.join();
59 
60   return 0;
61 }
62