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 // UNSUPPORTED: libcpp-has-no-threads
11 
12 // <condition_variable>
13 
14 // void
15 //   notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
16 
17 #include <condition_variable>
18 #include <mutex>
19 #include <thread>
20 #include <chrono>
21 #include <cassert>
22 
23 std::condition_variable cv;
24 std::mutex mut;
25 
26 typedef std::chrono::milliseconds ms;
27 typedef std::chrono::high_resolution_clock Clock;
28 
func()29 void func()
30 {
31     std::unique_lock<std::mutex> lk(mut);
32     std::notify_all_at_thread_exit(cv, std::move(lk));
33     std::this_thread::sleep_for(ms(300));
34 }
35 
main()36 int main()
37 {
38     std::unique_lock<std::mutex> lk(mut);
39     std::thread t(func);
40     Clock::time_point t0 = Clock::now();
41     cv.wait(lk);
42     Clock::time_point t1 = Clock::now();
43     assert(t1-t0 > ms(250));
44     t.join();
45 }
46