Avoid Dispatch Global Concurrent Queues

This thread has been locked by a moderator.

I regularly see folks write code like this:

DispatchQueue.global().async {
    … do stuff …
}

This relies on a Dispatch global concurrent queue. Using such queues directly is almost always a mistake. That’s because a global concurrent queue might [1] overcommit — that is, start more threads than there are CPU cores — resulting in needless inefficiency. In the worse case this can trigger a phenomenon known as thread explosion, which is about as much fun as it sounds.

My general advice is that you avoid concurrent queues in almost all circumstances. For more background on this, see:

If you have any follow comments or questions, please start a new thread, tagging it with Dispatch, and I’ll respond there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Whether it will overcommit is a more complex question (-:

(r. 98175345)

Up vote post of eskimo
1.8k views