1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <condition_variable> 11 12 // void 13 // notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk); 14 15 #include <condition_variable> 16 #include <mutex> 17 #include <thread> 18 #include <chrono> 19 #include <cassert> 20 21 std::condition_variable cv; 22 std::mutex mut; 23 24 typedef std::chrono::milliseconds ms; 25 typedef std::chrono::high_resolution_clock Clock; 26 func()27void func() 28 { 29 std::unique_lock<std::mutex> lk(mut); 30 std::notify_all_at_thread_exit(cv, std::move(lk)); 31 std::this_thread::sleep_for(ms(300)); 32 } 33 main()34int main() 35 { 36 std::unique_lock<std::mutex> lk(mut); 37 std::thread(func).detach(); 38 Clock::time_point t0 = Clock::now(); 39 cv.wait(lk); 40 Clock::time_point t1 = Clock::now(); 41 assert(t1-t0 > ms(250)); 42 } 43