llvm-project
llvm-project copied to clipboard
[libc++][test] Fix race condition in condition_variable_any tests
Some tests in condition_variable_any use two shared_lock to guard, which does not work.
The fix is to make the writer to use unique_lock
@llvm/pr-subscribers-libcxx
Author: Hui (huixie90)
Changes
Full diff: https://github.com/llvm/llvm-project/pull/84788.diff
3 Files Affected:
- (modified) libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_token_pred.pass.cpp (+1-1)
- (modified) libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_token_pred.pass.cpp (+1-1)
- (modified) libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_token_pred.pass.cpp (+1-1)
diff --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_token_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_token_pred.pass.cpp
index 4ea60557d9f88c..7a39d1253a33cf 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_token_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_token_pred.pass.cpp
@@ -119,7 +119,7 @@ void test() {
bool flag = false;
auto thread = support::make_test_thread([&]() {
std::this_thread::sleep_for(2ms);
- Lock lock2{mutex};
+ std::unique_lock<Mutex> lock2{mutex};
flag = true;
cv.notify_all();
});
diff --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_token_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_token_pred.pass.cpp
index e96a3e8bd1bc0b..f322d8cfdc68fc 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_token_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_token_pred.pass.cpp
@@ -63,7 +63,7 @@ void test() {
bool flag = false;
auto thread = support::make_test_thread([&]() {
std::this_thread::sleep_for(std::chrono::milliseconds(2));
- Lock lock2{mutex};
+ std::unique_lock<Mutex> lock2{mutex};
flag = true;
cv.notify_all();
});
diff --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_token_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_token_pred.pass.cpp
index d649db025d755d..e7388b9ce0e176 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_token_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_token_pred.pass.cpp
@@ -119,7 +119,7 @@ void test() {
bool flag = false;
auto thread = support::make_test_thread([&]() {
std::this_thread::sleep_for(std::chrono::milliseconds(2));
- Lock lock2{mutex};
+ std::unique_lock<Mutex> lock2{mutex};
flag = true;
cv.notify_all();
});
:white_check_mark: With the latest revision this PR passed the Python code formatter.
:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.