blob: b61116702c5b553ee5f21ee3501302d27e0459ac [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-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 Hinnant3e519522010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <condition_variable>
11
12// class condition_variable_any;
13
14// template <class Lock>
15// void wait(Lock& lock);
16
17#include <condition_variable>
18#include <mutex>
19#include <thread>
20#include <cassert>
21
22std::condition_variable_any cv;
23
24typedef std::timed_mutex L0;
25typedef std::unique_lock<L0> L1;
26
27L0 m0;
28
29int test1 = 0;
30int test2 = 0;
31
32void f()
33{
34 L1 lk(m0);
35 assert(test2 == 0);
36 test1 = 1;
37 cv.notify_one();
38 while (test2 == 0)
39 cv.wait(lk);
40 assert(test2 != 0);
41}
42
43int main()
44{
45 L1 lk(m0);
46 std::thread t(f);
47 assert(test1 == 0);
48 while (test1 == 0)
49 cv.wait(lk);
50 assert(test1 != 0);
51 test2 = 1;
52 lk.unlock();
53 cv.notify_one();
54 t.join();
55}