diff --git a/stdlib/public/Concurrency/Task.cpp b/stdlib/public/Concurrency/Task.cpp index 1b0de154e2f49..25da2133323ed 100644 --- a/stdlib/public/Concurrency/Task.cpp +++ b/stdlib/public/Concurrency/Task.cpp @@ -1792,9 +1792,11 @@ static void swift_task_removeCancellationHandlerImpl( return; } + auto task = swift_task_getCurrent(); + assert(task->_private()._status().load(std::memory_order_relaxed).getInnermostRecord() == record && + "We expect that the popped record will be exactly first as well as that it is of the expected type"); if (auto poppedRecord = - popStatusRecordOfType(swift_task_getCurrent())) { - assert(record == poppedRecord && "The removed record did not match the expected record!"); + popStatusRecordOfType(task)) { swift_task_dealloc(record); } }