Search code examples
iosobjective-cmultithreadingconcurrencygrand-central-dispatch

How do serial queues differ from concurrent queues?


I'm very confused what serial vs concurrent queues are. Does concurrent allow a bunch of operations to be in the queue, and then split them up over available threads, while serial does the same, but limiting it to one thread and waiting for one at a time to finish?

The explanations in the documentation seem very confusing.


Solution

  • "serial" means that the blocks submitted to the queue are executed sequentially, i.e. the second block is not executed before the first one has finished. It does not mean that the blocks are executed on the same thread.

    "concurrent" means that the blocks submitted to the queue may execute concurrently (on different threads).

    In both cases, GCD uses a "thread pool" to execute blocks, so you cannot know on which thread a block will be executed. The only exception is the "main queue" which executes all blocks on the main thread.