[libcxx-commits] [libcxx] [libc++] Fix sporadic test failure in condition_variable notify_all test (PR #97622)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jul 7 07:01:23 PDT 2024
https://github.com/huixie90 updated https://github.com/llvm/llvm-project/pull/97622
>From 2fa1335913ee6eb980b3a8541c5b2aa5c224725a Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Wed, 3 Jul 2024 12:53:14 +0100
Subject: [PATCH 1/3] [libc++][test] fix sporiadic test failure in
condition_variable notify_all test
---
.../thread.condition.condvar/notify_all.pass.cpp | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
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 e0d587dbca0e9a..995e4c9f72f8bc 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 <atomic>
#include <condition_variable>
#include <mutex>
#include <thread>
@@ -29,10 +30,13 @@ int test0 = 0;
int test1 = 0;
int test2 = 0;
+std::atomic<int> ready_count = 0;
+
void f1()
{
std::unique_lock<std::mutex> lk(mut);
assert(test1 == 0);
+ ready_count.fetch_add(1);
while (test1 == 0)
cv.wait(lk);
assert(test1 == 1);
@@ -43,6 +47,7 @@ void f2()
{
std::unique_lock<std::mutex> lk(mut);
assert(test2 == 0);
+ ready_count.fetch_add(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_lock<std::mutex>lk(mut);
test1 = 1;
>From 72ba574b407edc893c359ea508fcc4d246145985 Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Sat, 6 Jul 2024 10:49:23 +0100
Subject: [PATCH 2/3] CI
---
.../thread.condition.condvar/notify_all.pass.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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 995e4c9f72f8bc..673e8dbf159a8a 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
@@ -30,13 +30,13 @@ int test0 = 0;
int test1 = 0;
int test2 = 0;
-std::atomic<int> ready_count = 0;
+std::atomic<int> ready_count(0);
void f1()
{
std::unique_lock<std::mutex> lk(mut);
assert(test1 == 0);
- ready_count.fetch_add(1);
+ ready_count += 1;
while (test1 == 0)
cv.wait(lk);
assert(test1 == 1);
@@ -47,7 +47,7 @@ void f2()
{
std::unique_lock<std::mutex> lk(mut);
assert(test2 == 0);
- ready_count.fetch_add(1);
+ ready_count += 1;
while (test2 == 0)
cv.wait(lk);
assert(test2 == 1);
>From ef1ca35555becd1d4e489ab6df343d8edfff3768 Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Sun, 7 Jul 2024 15:01:10 +0100
Subject: [PATCH 3/3] CI
---
.../thread.condition.condvar/notify_all.pass.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 673e8dbf159a8a..68881756ac6fdc 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
@@ -59,7 +59,7 @@ int main(int, char**)
std::thread t1 = support::make_test_thread(f1);
std::thread t2 = support::make_test_thread(f2);
while (ready_count.load() != 2) {
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
{
std::unique_lock<std::mutex>lk(mut);
More information about the libcxx-commits
mailing list