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;
14 
15 // void wait(unique_lock<mutex>& lock);
16 
17 #include <condition_variable>
18 #include <mutex>
19 #include <thread>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 
24 std::condition_variable cv;
25 std::mutex mut;
26 
27 int test1 = 0;
28 int test2 = 0;
29 
30 void f()
31 {
32     std::unique_lock<std::mutex> lk(mut);
33     assert(test2 == 0);
34     test1 = 1;
35     cv.notify_one();
36     while (test2 == 0)
37         cv.wait(lk);
38     assert(test2 != 0);
39 }
40 
41 int main(int, char**)
42 {
43     std::unique_lock<std::mutex>lk(mut);
44     std::thread t(f);
45     assert(test1 == 0);
46     while (test1 == 0)
47         cv.wait(lk);
48     assert(test1 != 0);
49     test2 = 1;
50     lk.unlock();
51     cv.notify_one();
52     t.join();
53 
54   return 0;
55 }
56