10.4 · Actors, reentrancy, isolated, nonisolated, global actors and @MainActor
Actors make “who may touch this state” a property the compiler checks. The price is that every hop is an await, and every await is a chance for the world to change.
Mental model. An actor is a serial gatekeeper for its state. Inside, code runs one piece at a time; between two awaits, anything can happen.
Actors
Isolation, reentrancy and what an actor does not guarantee.
- What does an actor guarantee, and what is actor reentrancy?
An actor is a reference type that protects its mutable state: only one piece of code runs on the actor at a time, and from outside you may touch its isolated…
Isolation domains
Global actors, <code>@MainActor</code>, <code>isolated</code> and <code>nonisolated</code>.
- How do @MainActor, global actors, isolated and nonisolated work, and how does isolation propagate?
Every piece of code has an isolation domain: an actor instance, a global actor, or none (nonisolated). A global actor is a single, shared actor you attach with…
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.5 · Region-based isolation, sending, and migrating to Swift 6
- 10.6 · Continuations and bridging GCD, Combine and callback APIs
- 10.7 · Deadlocks, main-actor hops, Thread Sanitizer and Instruments
- 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