[mlir] Update Ch-2.md (#121379)
[llvm-project.git] / libcxx / test / std / thread / thread.condition / thread.condition.condvar / destructor.pass.cpp
blob530cc1264f3b69348f6141e36159bbb29683b87c
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-threads
11 // <condition_variable>
13 // class condition_variable;
15 // ~condition_variable();
17 #include <condition_variable>
18 #include <mutex>
19 #include <thread>
20 #include <cassert>
22 #include "make_test_thread.h"
23 #include "test_macros.h"
25 std::condition_variable* cv;
26 std::mutex m;
27 typedef std::unique_lock<std::mutex> Lock;
29 bool f_ready = false;
30 bool g_ready = false;
32 void f()
34 Lock lk(m);
35 f_ready = true;
36 cv->notify_one();
37 delete cv;
40 void g()
42 Lock lk(m);
43 g_ready = true;
44 cv->notify_one();
45 while (!f_ready)
46 cv->wait(lk);
49 int main(int, char**)
51 cv = new std::condition_variable;
52 std::thread th2 = support::make_test_thread(g);
53 Lock lk(m);
54 while (!g_ready)
55 cv->wait(lk);
56 lk.unlock();
57 std::thread th1 = support::make_test_thread(f);
58 th1.join();
59 th2.join();
61 return 0;