File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
libcxx/test/std/thread/thread.condition/thread.condition.condvar Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 1414
1515// void notify_all();
1616
17+ #include < atomic>
1718#include < condition_variable>
1819#include < mutex>
1920#include < thread>
@@ -29,10 +30,13 @@ int test0 = 0;
2930int test1 = 0 ;
3031int test2 = 0 ;
3132
33+ std::atomic<int > ready_count (0 );
34+
3235void f1 ()
3336{
3437 std::unique_lock<std::mutex> lk (mut);
3538 assert (test1 == 0 );
39+ ready_count += 1 ;
3640 while (test1 == 0 )
3741 cv.wait (lk);
3842 assert (test1 == 1 );
@@ -43,6 +47,7 @@ void f2()
4347{
4448 std::unique_lock<std::mutex> lk (mut);
4549 assert (test2 == 0 );
50+ ready_count += 1 ;
4651 while (test2 == 0 )
4752 cv.wait (lk);
4853 assert (test2 == 1 );
@@ -53,7 +58,9 @@ int main(int, char**)
5358{
5459 std::thread t1 = support::make_test_thread (f1);
5560 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+ }
5764 {
5865 std::unique_lock<std::mutex>lk (mut);
5966 test1 = 1 ;
You can’t perform that action at this time.
0 commit comments