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