Skip to content

Commit 7c3b06d

Browse files
committed
[Concurrency] Avoid de-escalating a task when racing to escalate.
Reload oldPriority each time through the compare_exchange loop. Without this, we might race with another escalating thread and end up trying to set a priority that's lower or equal to the priority set by the other thread. This results in an assertion failure when asserts are enabled, or attempt to lower the priority of the task when asserts are not enabled. rdar://147888768
1 parent 97b249b commit 7c3b06d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

stdlib/public/Concurrency/TaskStatus.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,9 @@ static swift_task_escalateImpl(AsyncTask *task, JobPriority newPriority) {
11391139
auto newStatus = oldStatus;
11401140

11411141
while (true) {
1142+
// Ensure oldPriority is up to date if we retry the compare_exchange.
1143+
oldPriority = oldStatus.getStoredPriority();
1144+
11421145
// Fast path: check that the stored priority is already at least
11431146
// as high as the desired priority.
11441147
if (oldPriority >= newPriority) {

0 commit comments

Comments
 (0)