Skip to content

Commit e98e431

Browse files
authored
Merge pull request swiftlang#75948 from RSilicon/atom
Specify atomicity for compare_exchange_strong
2 parents cd1f02d + ea2b116 commit e98e431

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,9 @@ AsyncTask *TaskGroupBase::claimWaitingTask() {
653653
"task is present!");
654654

655655
auto waitingTask = waitQueue.load(std::memory_order_acquire);
656-
if (!waitQueue.compare_exchange_strong(waitingTask, nullptr)) {
656+
if (!waitQueue.compare_exchange_strong(waitingTask, nullptr,
657+
std::memory_order_release,
658+
std::memory_order_relaxed)) {
657659
swift_Concurrency_fatalError(0, "Failed to claim waitingTask!");
658660
}
659661
return waitingTask;
@@ -1403,7 +1405,9 @@ void DiscardingTaskGroup::offer(AsyncTask *completedTask, AsyncContext *context)
14031405
// allows a single task to get the waiting task and attempt to complete it.
14041406
// As another offer gets to run, it will have either a different waiting task, or no waiting task at all.
14051407
auto waitingTask = waitQueue.load(std::memory_order_acquire);
1406-
if (!waitQueue.compare_exchange_strong(waitingTask, nullptr)) {
1408+
if (!waitQueue.compare_exchange_strong(waitingTask, nullptr,
1409+
std::memory_order_release,
1410+
std::memory_order_relaxed)) {
14071411
swift_Concurrency_fatalError(0, "Failed to claim waitingTask!");
14081412
}
14091413
assert(waitingTask && "status claimed to have waitingTask but waitQueue was empty!");

0 commit comments

Comments
 (0)