-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[libc++] Fix sporadic test failure in condition_variable notify_all test #97622
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
the
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
label
Jul 3, 2024
@llvm/pr-subscribers-libcxx Author: Hui (huixie90) ChangesFull diff: https://github.com/llvm/llvm-project/pull/97622.diff 1 Files Affected:
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 e0d587dbca0e9..995e4c9f72f8b 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;
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
ldionne
changed the title
[libc++][test] fix sporiadic test failure in condition_variable notify_all test
[libc++] Fix sporadic test failure in condition_variable notify_all test
Jul 3, 2024
ldionne
approved these changes
Jul 3, 2024
void f1() | ||
{ | ||
std::unique_lock<std::mutex> lk(mut); | ||
assert(test1 == 0); | ||
ready_count.fetch_add(1); |
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.
Slight preference for ready_count += 1
since that's easier to read.
aaryanshukla
pushed a commit
to aaryanshukla/llvm-project
that referenced
this pull request
Jul 14, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #95944