10.1 · Queues, QoS, barriers, groups, semaphores and sources
GCD is still under a large part of every Apple platform, including the parts Swift concurrency runs on. It is a tool for describing what runs where and when, not a thread API.
Mental model. You do not manage threads. You submit work to queues, and the system decides which threads run it. Ordering and safety come from which queue, not from which thread.
Queues and coordination
Serial and concurrent queues, QoS, targets, and the tools for waiting.
- What is the difference between serial and concurrent queues and between sync and async, and what do QoS and target queues do?
Two independent choices describe a dispatch. The queue decides how its tasks run relative to each other: a serial queue runs one task at a time, in the order… - How do barriers, groups, semaphores and dispatch sources coordinate work?
A barrier block (flags: .barrier) on a concurrent queue waits for all earlier blocks to finish, runs alone, and then lets later blocks resume. That gives the…
When it goes wrong
Thread explosion, priority inversion and how the system helps.
- What are thread explosion and priority inversion, and how do QoS and the system help?
Thread explosion happens when you submit many blocks to a concurrent queue and those blocks block (waiting on I/O, a lock or a sync call). GCD sees idle CPU…
More in Concurrency
- 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.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