Blog
6 days ago
Swift Concurrency: Actors, Executors, and Their Interaction with Threads
The Mechanics: An Actor doesn't achieve thread safety by magic; it relies entirely on its underlying SerialExecutor to orchestrate the sequential execution of its Jobs. Customization (iOS 18+): Developers can now override the default system behavior by injecting custom SerialExecutor and TaskExecutor implementations. The Danger: Without a robust executor, the actor keyword is just syntactic sugar. We prove this by building a naive custom executor that instantly causes EXC_BAD_ACCESS data races, and then we fix it using a serial DispatchQueue. The Blueprint: We break down exactly how the Swift runtime determines which executor to use (Default vs. Custom Task/Serial) with a clear flowchart for complex asynchronous contexts.
Source: HackerNoon →