Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / thread / thread.condition / thread.condition.condvarany / destructor.pass.cpp
blob6f5111a03b78a533666d19b9d124c6c7c5e66d8f
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_any;
15 // ~condition_variable_any();
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_any* cv;
26 std::mutex m;
28 bool f_ready = false;
29 bool g_ready = false;
31 void f()
33 m.lock();
34 f_ready = true;
35 cv->notify_one();
36 delete cv;
37 m.unlock();
40 void g()
42 m.lock();
43 g_ready = true;
44 cv->notify_one();
45 while (!f_ready)
46 cv->wait(m);
47 m.unlock();
50 int main(int, char**)
52 cv = new std::condition_variable_any;
53 std::thread th2 = support::make_test_thread(g);
54 m.lock();
55 while (!g_ready)
56 cv->wait(m);
57 m.unlock();
58 std::thread th1 = support::make_test_thread(f);
59 th1.join();
60 th2.join();
62 return 0;