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 // notify_all_at_thread_exit(...) requires move semantics to transfer the 12 // unique_lock. 13 // UNSUPPORTED: c++03 14 15 // <condition_variable> 16 17 // void 18 // notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk); 19 20 #include <condition_variable> 21 #include <mutex> 22 #include <thread> 23 #include <chrono> 24 #include <cassert> 25 26 #include "test_macros.h" 27 28 std::condition_variable cv; 29 std::mutex mut; 30 31 typedef std::chrono::milliseconds ms; 32 typedef std::chrono::high_resolution_clock Clock; 33 34 void func() 35 { 36 std::unique_lock<std::mutex> lk(mut); 37 std::notify_all_at_thread_exit(cv, std::move(lk)); 38 std::this_thread::sleep_for(ms(300)); 39 } 40 41 int main(int, char**) 42 { 43 std::unique_lock<std::mutex> lk(mut); 44 std::thread t(func); 45 Clock::time_point t0 = Clock::now(); 46 cv.wait(lk); 47 Clock::time_point t1 = Clock::now(); 48 assert(t1-t0 > ms(250)); 49 t.join(); 50 51 return 0; 52 } 53