mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
I have identified the following conceptual synchronization points at which task data and computation can cross thread boundaries. We need to model these in TSan to avoid false positives: Awaiting an async task (`AsyncTask::waitFuture`), which has two cases: 1) The task has completed (`AsyncTask::completeFuture`). Everything that happened during task execution "happened before" before the point where we access its result. We synchronize on the *awaited* task. 2) The task is still executing: the current execution is suspended and the waiting task is put into the list of "waiters". Once the awaited task completes, the waiters will be scheduled. In this case, we synchronize on the *waiting* task. Note: there is a similar relationship for task groups which I still have to investigate. I will follow-up with an additional patch and tests. Actor job execution (`swift::runJobInExecutorContext`): Job scheduling (`swift::swift_task_enqueue`) precedes/happens before job execution. Also all job executions (switching actors or suspend/resume) are serially ordered. Note: the happens-before edge for schedule->execute isn't strictly needed in most cases since scheduling calls through to libdispatch's `dispatch_async_f`, which we already intercept and model in TSan. However, I am trying to model Swift Task semantics to increase the chance of things to continue to work in case the "task backend" is switched out. rdar://74256733
23 KiB
23 KiB