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 // template <class Lock> 16 // void wait(Lock& lock); 17 18 #include <condition_variable> 19 #include <mutex> 20 #include <thread> 21 #include <cassert> 22 23 #include "test_macros.h" 24 25 std::condition_variable_any cv; 26 27 typedef std::timed_mutex L0; 28 typedef std::unique_lock<L0> L1; 29 30 L0 m0; 31 32 int test1 = 0; 33 int test2 = 0; 34 35 void f() 36 { 37 L1 lk(m0); 38 assert(test2 == 0); 39 test1 = 1; 40 cv.notify_one(); 41 while (test2 == 0) 42 cv.wait(lk); 43 assert(test2 != 0); 44 } 45 46 int main(int, char**) 47 { 48 L1 lk(m0); 49 std::thread t(f); 50 assert(test1 == 0); 51 while (test1 == 0) 52 cv.wait(lk); 53 assert(test1 != 0); 54 test2 = 1; 55 lk.unlock(); 56 cv.notify_one(); 57 t.join(); 58 59 return 0; 60 } 61