Skip to content

Commit e98195f

Browse files
authored
[libc++] Fix another potentially flaky atomic test. (#71011)
This is a follow-up to #70436.
1 parent 5a9b996 commit e98195f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_notify_all.pass.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ struct TestFn {
3939
{
4040
A a(T(1));
4141
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) {
4345
assert(std::atomic_load(&a) == T(1));
46+
is_ready[index].store(true);
47+
4448
std::atomic_wait(&a, T(1));
4549
assert(std::atomic_load(&a) == T(3));
4650
};
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);
5053

54+
while (!is_ready[0] || !is_ready[1]) {
55+
// Spin
56+
}
5157
std::atomic_store(&a, T(3));
5258
std::atomic_notify_all(&a);
5359
t1.join();

0 commit comments

Comments
 (0)