How does DispatchQueue.global() differ from your own concurrent queue?
The essence
DispatchQueue.global(qos:) is one of the system concurrent queues (one per QoS level), shared by the whole process: Apple frameworks and third-party libraries put their work there too. Your own DispatchQueue(label:attributes: .concurrent) is a private object that only you control.
Practical differences:
- Barrier.
.barrieronly makes sense on your own concurrent queue. On a global queue the flag is ignored (otherwise one barrier would stall the whole system) — the block runs as a plainasync. - Isolation. Only your tasks run on your queue, so
sync/barriergive predictable guarantees and it can serve as a reader-writer lock. - Control. Your own queue can be suspended (
suspend/resume), given atargetqueue, anautoreleaseFrequency, a default QoS; a global one cannot. - Debugging. The
labelof your queue shows up in Instruments and crash stacks. - Resources. By default your queue targets the global queue of the same QoS, so threads come from the same pool — it creates no new threads.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep