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++98, 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 std::condition_variable cv; 27 std::mutex mut; 28 29 typedef std::chrono::milliseconds ms; 30 typedef std::chrono::high_resolution_clock Clock; 31 32 void func() 33 { 34 std::unique_lock<std::mutex> lk(mut); 35 std::notify_all_at_thread_exit(cv, std::move(lk)); 36 std::this_thread::sleep_for(ms(300)); 37 } 38 39 int main(int, char**) 40 { 41 std::unique_lock<std::mutex> lk(mut); 42 std::thread t(func); 43 Clock::time_point t0 = Clock::now(); 44 cv.wait(lk); 45 Clock::time_point t1 = Clock::now(); 46 assert(t1-t0 > ms(250)); 47 t.join(); 48 49 return 0; 50 } 51