File tree 1 file changed +8
-1
lines changed
libcxx/test/std/thread/thread.condition/thread.condition.condvar
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 14
14
15
15
// void notify_all();
16
16
17
+ #include < atomic>
17
18
#include < condition_variable>
18
19
#include < mutex>
19
20
#include < thread>
@@ -29,10 +30,13 @@ int test0 = 0;
29
30
int test1 = 0 ;
30
31
int test2 = 0 ;
31
32
33
+ std::atomic<int > ready_count (0 );
34
+
32
35
void f1 ()
33
36
{
34
37
std::unique_lock<std::mutex> lk (mut);
35
38
assert (test1 == 0 );
39
+ ready_count += 1 ;
36
40
while (test1 == 0 )
37
41
cv.wait (lk);
38
42
assert (test1 == 1 );
@@ -43,6 +47,7 @@ void f2()
43
47
{
44
48
std::unique_lock<std::mutex> lk (mut);
45
49
assert (test2 == 0 );
50
+ ready_count += 1 ;
46
51
while (test2 == 0 )
47
52
cv.wait (lk);
48
53
assert (test2 == 1 );
@@ -53,7 +58,9 @@ int main(int, char**)
53
58
{
54
59
std::thread t1 = support::make_test_thread (f1);
55
60
std::thread t2 = support::make_test_thread (f2);
56
- std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
61
+ while (ready_count.load () != 2 ) {
62
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
63
+ }
57
64
{
58
65
std::unique_lock<std::mutex>lk (mut);
59
66
test1 = 1 ;
You can’t perform that action at this time.
0 commit comments