10.7 · Deadlocks, main-actor hops, Thread Sanitizer and Instruments
Concurrency bugs are the ones you cannot reproduce on demand. You need tools that catch them before they bite, and a short list of patterns to recognise.
Mental model. Do not hunt a race by reading. Make the machine report it: sanitizers at test time, instruments at profile time, compiler errors at build time.
Finding the bugs
Deadlocks, races, actor hops, and the tools for each.
- How do you find and fix deadlocks, data races and slow main-actor hops?
Data races (two threads touching the same memory, one writing, with no synchronisation) are found by Thread Sanitizer (Product ▸ Scheme ▸ Diagnostics ▸ Thread…
More in Concurrency
- 10.1 · Queues, QoS, barriers, groups, semaphores and sources
- 10.2 · Operation, OperationQueue, dependencies and cancellation
- 10.3 · async/await, tasks, task groups, cancellation and task locals
- 10.4 · Actors, reentrancy, isolated, nonisolated, global actors and @MainActor
- 10.5 · Region-based isolation, sending, and migrating to Swift 6
- 10.6 · Continuations and bridging GCD, Combine and callback APIs
- 10.8 · Task groups, async let, cancellation and task locals in practice
- 10.9 · Isolation rules, isolated parameters, global actors, main-actor hops and default isolation
- 10.10 · Sendable rules, locks versus actors, and the escape hatches
- 10.11 · Groups, semaphores, parallel loops, operation dependencies, QoS and timers
- 10.12 · AsyncStream buffering, continuation misuse and notifications as async sequences