File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -39,15 +39,21 @@ struct TestFn {
39
39
{
40
40
A a (T (1 ));
41
41
static_assert (noexcept (std::atomic_notify_all (&a)), " " );
42
- auto f = [&]() {
42
+
43
+ std::atomic<bool > is_ready[2 ] = {false , false };
44
+ auto f = [&](int index) {
43
45
assert (std::atomic_load (&a) == T (1 ));
46
+ is_ready[index].store (true );
47
+
44
48
std::atomic_wait (&a, T (1 ));
45
49
assert (std::atomic_load (&a) == T (3 ));
46
50
};
47
- std::thread t1 = support::make_test_thread (f);
48
- std::thread t2 = support::make_test_thread (f);
49
- std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
51
+ std::thread t1 = support::make_test_thread (f, /* index=*/ 0 );
52
+ std::thread t2 = support::make_test_thread (f, /* index=*/ 1 );
50
53
54
+ while (!is_ready[0 ] || !is_ready[1 ]) {
55
+ // Spin
56
+ }
51
57
std::atomic_store (&a, T (3 ));
52
58
std::atomic_notify_all (&a);
53
59
t1.join ();
You can’t perform that action at this time.
0 commit comments