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 // UNSUPPORTED: libcpp-has-no-threads 11 12 // <condition_variable> 13 14 // class condition_variable_any; 15 16 // ~condition_variable_any(); 17 18 #include <condition_variable> 19 #include <mutex> 20 #include <thread> 21 #include <cassert> 22 23 std::condition_variable_any* cv; 24 std::mutex m; 25 26 bool f_ready = false; 27 bool g_ready = false; 28 f()29void f() 30 { 31 m.lock(); 32 f_ready = true; 33 cv->notify_one(); 34 delete cv; 35 m.unlock(); 36 } 37 g()38void g() 39 { 40 m.lock(); 41 g_ready = true; 42 cv->notify_one(); 43 while (!f_ready) 44 cv->wait(m); 45 m.unlock(); 46 } 47 main()48int main() 49 { 50 cv = new std::condition_variable_any; 51 std::thread th2(g); 52 m.lock(); 53 while (!g_ready) 54 cv->wait(m); 55 m.unlock(); 56 std::thread th1(f); 57 th1.join(); 58 th2.join(); 59 } 60