Queues

Dispatch queues are GCD’s fundamental structure. A queue is a list of work items. A queue, by definition, is drained in a FIFO manner – first in, first out order. GCD maintains a thread pool where it actually runs the work items that are pulled from queues. Work items can be submitted as a block or a function pointer/context pair. Each serial queue is backed by a global queue.

There are two kinds of queues, serial queues and global queues. Serial queues dispatch their work items and complete them in FIFO order. Serial queues will not have two different work items executing simultaneously. This is what serializes access to sensitive data structures. The main queue, the queue for doing work on the main thread, is a serial queue.

A global ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.