[libc++] Remove duplicated _LIBCPP_HIDE_FROM_ABI from a few declarations (#122323)
[llvm-project.git] / libcxx / test / std / thread / thread.condition / thread.condition.condvarany / notify_one.pass.cpp
blob4fc436b728bb9a84eb0e5ec14a1d4feeaf88934e
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
10 // ALLOW_RETRIES: 2
12 // <condition_variable>
14 // class condition_variable_any;
16 // void notify_one();
18 #include <condition_variable>
19 #include <mutex>
20 #include <thread>
21 #include <cassert>
23 #include "make_test_thread.h"
24 #include "test_macros.h"
26 std::condition_variable_any cv;
28 typedef std::timed_mutex L0;
29 typedef std::unique_lock<L0> L1;
31 L0 m0;
33 int test0 = 0;
34 int test1 = 0;
35 int test2 = 0;
37 void f1()
39 L1 lk(m0);
40 assert(test1 == 0);
41 while (test1 == 0)
42 cv.wait(lk);
43 assert(test1 == 1);
44 test1 = 2;
47 void f2()
49 L1 lk(m0);
50 assert(test2 == 0);
51 while (test2 == 0)
52 cv.wait(lk);
53 assert(test2 == 1);
54 test2 = 2;
57 int main(int, char**)
59 std::thread t1 = support::make_test_thread(f1);
60 std::thread t2 = support::make_test_thread(f2);
61 std::this_thread::sleep_for(std::chrono::milliseconds(100));
63 L1 lk(m0);
64 test1 = 1;
65 test2 = 1;
67 cv.notify_one();
69 std::this_thread::sleep_for(std::chrono::milliseconds(100));
70 L1 lk(m0);
72 if (test1 == 2)
74 t1.join();
75 test1 = 0;
77 else if (test2 == 2)
79 t2.join();
80 test2 = 0;
82 else
83 assert(false);
84 cv.notify_one();
86 std::this_thread::sleep_for(std::chrono::milliseconds(100));
87 L1 lk(m0);
89 if (test1 == 2)
91 t1.join();
92 test1 = 0;
94 else if (test2 == 2)
96 t2.join();
97 test2 = 0;
99 else
100 assert(false);
102 return 0;