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 // void notify_all();
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_any cv;
25 
26 typedef std::timed_mutex L0;
27 typedef std::unique_lock<L0> L1;
28 
29 L0 m0;
30 
31 int test0 = 0;
32 int test1 = 0;
33 int test2 = 0;
34 
35 void f1()
36 {
37     L1 lk(m0);
38     assert(test1 == 0);
39     while (test1 == 0)
40         cv.wait(lk);
41     assert(test1 == 1);
42     test1 = 2;
43 }
44 
45 void f2()
46 {
47     L1 lk(m0);
48     assert(test2 == 0);
49     while (test2 == 0)
50         cv.wait(lk);
51     assert(test2 == 1);
52     test2 = 2;
53 }
54 
55 int main(int, char**)
56 {
57     std::thread t1(f1);
58     std::thread t2(f2);
59     std::this_thread::sleep_for(std::chrono::milliseconds(100));
60     {
61         L1 lk(m0);
62         test1 = 1;
63         test2 = 1;
64     }
65     cv.notify_all();
66     {
67         std::this_thread::sleep_for(std::chrono::milliseconds(100));
68         L1 lk(m0);
69     }
70     t1.join();
71     t2.join();
72     assert(test1 == 2);
73     assert(test2 == 2);
74 
75   return 0;
76 }
77