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