blob: 2b8772f92ed27ca5b9a7d80276e7edad32ce7fbe [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000011
12// <condition_variable>
13
14// void
15// notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
16
17#include <condition_variable>
Howard Hinnante6e4d012010-09-03 21:46:37 +000018#include <mutex>
19#include <thread>
20#include <chrono>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021#include <cassert>
22
Howard Hinnante6e4d012010-09-03 21:46:37 +000023std::condition_variable cv;
24std::mutex mut;
25
26typedef std::chrono::milliseconds ms;
27typedef std::chrono::high_resolution_clock Clock;
28
29void 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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036int main()
37{
Howard Hinnante6e4d012010-09-03 21:46:37 +000038 std::unique_lock<std::mutex> lk(mut);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070039 std::thread(func).detach();
Howard Hinnante6e4d012010-09-03 21:46:37 +000040 Clock::time_point t0 = Clock::now();
41 cv.wait(lk);
42 Clock::time_point t1 = Clock::now();
43 assert(t1-t0 > ms(250));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000044}