Skip to content

waitQueue.compare_exchange_strong in the true loop can be weak #70636

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

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions stdlib/public/Concurrency/TaskGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,14 +1779,14 @@ reevaluate_if_taskgroup_has_results:;
// ==== 3) Add to wait queue -------------------------------------------------
assert(assumed.readyTasks(this) == 0);
_swift_tsan_release(static_cast<Job *>(waitingTask));
if (!hasSuspended) {
waitingTask->flagAsSuspendedOnTaskGroup(asAbstract(this));
hasSuspended = true;
}
while (true) {
if (!hasSuspended) {
hasSuspended = true;
waitingTask->flagAsSuspendedOnTaskGroup(asAbstract(this));
}
// Put the waiting task at the beginning of the wait queue.
SWIFT_TASK_GROUP_DEBUG_LOG(this, "WATCH OUT, SET WAITER ONTO waitQueue.head = %p", waitQueue.load(std::memory_order_relaxed));
if (waitQueue.compare_exchange_strong(
if (waitQueue.compare_exchange_weak(
waitHead, waitingTask,
/*success*/ std::memory_order_release,
/*failure*/ std::memory_order_acquire)) {
Expand Down Expand Up @@ -1941,13 +1941,13 @@ void TaskGroupBase::waitAll(SwiftError* bodyError, AsyncTask *waitingTask,

auto waitHead = waitQueue.load(std::memory_order_acquire);
_swift_tsan_release(static_cast<Job *>(waitingTask));
if (!hasSuspended) {
waitingTask->flagAsSuspendedOnTaskGroup(asAbstract(this));
hasSuspended = true;
}
while (true) {
if (!hasSuspended) {
hasSuspended = true;
waitingTask->flagAsSuspendedOnTaskGroup(asAbstract(this));
}
// Put the waiting task at the beginning of the wait queue.
if (waitQueue.compare_exchange_strong(
if (waitQueue.compare_exchange_weak(
waitHead, waitingTask,
/*success*/ std::memory_order_release,
/*failure*/ std::memory_order_acquire)) {
Expand Down