swift
2380060f - When waiting on a task, escalate it before enqueuing the waiting task.

Commit
3 years ago
When waiting on a task, escalate it before enqueuing the waiting task. As soon as the waiting task is successfully enqueued on the blocking task, both tasks have to be considered invalidated because the blocking task can concurrently complete and resume its waiters: - The waiting task ensures that the blocking task is valid while it's waiting. However, that's measured from the perspective of the waiting task, not from the perspective of the thread that was previously executing it. As soon as the waiting task is resumed, the wait call completes and the validity guarantee on the blocking task disappears, so the blocking task must be treated as invalidated. - The waiting task ensures that it is valid as long as it isn't complete. Since it's trying to wait, it must not be complete. However, as soon we resume it, it can complete, so the waiting task must also be treated as invalidated. This is one of those things that's not really easy to test, and the need for a fix is pretty urgent, so I'm submitting this patch without a test. I'll try to land a race test that demonstrates the bug in the next few days. @kavon deserves all the credit here for some truly heroic debugging and finally recognizing the flaw in the code; I'm just popping in at the last minute to sheepishly patch the bug. Fixes rdar://92666987
Author
Committer
Parents
Loading