1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <condition_variable>
11 
12 // class condition_variable_any;
13 
14 // ~condition_variable_any();
15 
16 #include <condition_variable>
17 #include <mutex>
18 #include <thread>
19 #include <cassert>
20 
21 std::condition_variable_any* cv;
22 std::mutex m;
23 
24 bool f_ready = false;
25 bool g_ready = false;
26 
f()27 void f()
28 {
29     m.lock();
30     f_ready = true;
31     cv->notify_one();
32     delete cv;
33     m.unlock();
34 }
35 
g()36 void g()
37 {
38     m.lock();
39     g_ready = true;
40     cv->notify_one();
41     while (!f_ready)
42         cv->wait(m);
43     m.unlock();
44 }
45 
main()46 int main()
47 {
48     cv = new std::condition_variable_any;
49     std::thread th2(g);
50     m.lock();
51     while (!g_ready)
52         cv->wait(m);
53     m.unlock();
54     std::thread th1(f);
55     th1.join();
56     th2.join();
57 }
58