blob: f5c8926e34b3a986d4df38f429578a4ea968b381 [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//===----------------------------------------------------------------------===//
Jonathan Roelofsb3fcc672014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant3e519522010-05-11 19:42:16 +000011
12// <condition_variable>
13
14// class condition_variable_any;
15
16// template <class Lock>
17// void wait(Lock& lock);
18
19#include <condition_variable>
20#include <mutex>
21#include <thread>
22#include <cassert>
23
24std::condition_variable_any cv;
25
26typedef std::timed_mutex L0;
27typedef std::unique_lock<L0> L1;
28
29L0 m0;
30
31int test1 = 0;
32int test2 = 0;
33
34void f()
35{
36 L1 lk(m0);
37 assert(test2 == 0);
38 test1 = 1;
39 cv.notify_one();
40 while (test2 == 0)
41 cv.wait(lk);
42 assert(test2 != 0);
43}
44
45int main()
46{
47 L1 lk(m0);
48 std::thread t(f);
49 assert(test1 == 0);
50 while (test1 == 0)
51 cv.wait(lk);
52 assert(test1 != 0);
53 test2 = 1;
54 lk.unlock();
55 cv.notify_one();
56 t.join();
57}