-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Fix flakiness in atomic_notify_all.pass.cpp
#70436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Avoid relying on sleep for synchronization.
@llvm/pr-subscribers-libcxx Author: Konstantin Varlamov (var-const) ChangesAvoid relying on sleep for synchronization. Full diff: https://github.com/llvm/llvm-project/pull/70436.diff 1 Files Affected:
diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_notify_all.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_notify_all.pass.cpp
index d22ea426057113b..b96691735a4ccbd 100644
--- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_notify_all.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_notify_all.pass.cpp
@@ -56,15 +56,21 @@ struct TestFn {
{
volatile A a(T(2));
static_assert(noexcept(std::atomic_notify_all(&a)), "");
- auto f = [&]() {
+
+ std::atomic<bool> is_ready[2] = {false, false};
+ auto f = [&](int index) {
assert(std::atomic_load(&a) == T(2));
+ is_ready[index].store(true);
+
std::atomic_wait(&a, T(2));
assert(std::atomic_load(&a) == T(4));
};
- std::thread t1 = support::make_test_thread(f);
- std::thread t2 = support::make_test_thread(f);
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ std::thread t1 = support::make_test_thread(f, /*index=*/0);
+ std::thread t2 = support::make_test_thread(f, /*index=*/1);
+ while (!is_ready[0] || !is_ready[1]) {
+ // Spin
+ }
std::atomic_store(&a, T(4));
std::atomic_notify_all(&a);
t1.join();
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
@@ -56,15 +56,21 @@ struct TestFn { | |||
{ | |||
volatile A a(T(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test point above this test is still relying on sleep to be long enough. (The first assertion could still fail if the test thread started really slowly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Uploaded #71011
This is a follow-up to llvm#70436.
This is a follow-up to #70436.
This is a follow-up to llvm/llvm-project#70436. NOKEYCHECK=True GitOrigin-RevId: e98195f318375978e3e0b153cade8bb3a05029bb
Avoid relying on sleep for synchronization.