Skip to content

Commit 1c86195

Browse files
committed
[Concurrency] Warn about deadlock potential in withTaskCancellationHandler docs.
withTaskCancellationHandler gets called with the task status record lock held, so care needs to be taken if the cancellation handler acquires any locks of its own. Update the docs comment to describe this. rdar://111686260
1 parent 72337ef commit 1c86195

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ import Swift
2424
/// operation is running code that never checks for cancellation, a cancellation
2525
/// handler still runs and provides a chance to run some cleanup code.
2626
///
27+
/// Cancellation handlers which acquire locks must take care to avoid deadlock.
28+
/// The cancellation handler may be invoked while holding internal locks
29+
/// associated with the task or other tasks. Other operations on the task, such
30+
/// as resuming a continuation, may acquire these same internal locks.
31+
/// Therefore, if a cancellation handler must acquire a lock, other code should
32+
/// not cancel tasks or resume continuations while holding that lock.
33+
///
2734
/// Doesn't check for cancellation, and always executes the passed `operation`.
2835
///
2936
/// The `operation` executes on the calling execution context and does not suspend by itself,

0 commit comments

Comments
 (0)