[libcxx-commits] [libcxx] 81e2693 - [libc++][test] Fix race condition in condition_variable_any tests (#84788)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Mar 24 13:52:51 PDT 2024
Author: Hui
Date: 2024-03-24T20:52:47Z
New Revision: 81e2693c1202d6c4e48dbf2d985153b03cfccb79
URL: https://github.com/llvm/llvm-project/commit/81e2693c1202d6c4e48dbf2d985153b03cfccb79
DIFF: https://github.com/llvm/llvm-project/commit/81e2693c1202d6c4e48dbf2d985153b03cfccb79.diff
LOG: [libc++][test] Fix race condition in condition_variable_any tests (#84788)
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`
Added:
Modified:
libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_token_pred.pass.cpp
libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_token_pred.pass.cpp
libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_token_pred.pass.cpp
Removed:
################################################################################
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();
});
More information about the libcxx-commits
mailing list