diff --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp index e0d587dbca0e9..68881756ac6fd 100644 --- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp +++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp @@ -14,6 +14,7 @@ // void notify_all(); +#include #include #include #include @@ -29,10 +30,13 @@ int test0 = 0; int test1 = 0; int test2 = 0; +std::atomic ready_count(0); + void f1() { std::unique_lock lk(mut); assert(test1 == 0); + ready_count += 1; while (test1 == 0) cv.wait(lk); assert(test1 == 1); @@ -43,6 +47,7 @@ void f2() { std::unique_lock lk(mut); assert(test2 == 0); + ready_count += 1; while (test2 == 0) cv.wait(lk); assert(test2 == 1); @@ -53,7 +58,9 @@ int main(int, char**) { std::thread t1 = support::make_test_thread(f1); std::thread t2 = support::make_test_thread(f2); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + while (ready_count.load() != 2) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } { std::unique_locklk(mut); test1 = 1;