GCD Target Queues
August 14, 2014
This is the fourth post in a series about Grand Central Dispatch.
Come with me on a little detour, so we can take a look at a neat feature in GCD: target queues.
We begin our trip down this scenic byway by learning about a set of queues with very special properties: the global concurrent queues.
Global concurrent queues
GCD provides four global concurrent queues that are always available to your program. These queues are special, because they are automatically created by the library, can never be suspended, and treat barrier blocks like regular blocks. Because these queues are concurrent, all enqueued blocks will run in parallel.
Each of the four global concurrent queues has a different priority:
Blocks enqueued on a higher-priority queue will preempt blocks enqueued on a lower-priority queue.
These global concurrent queues play the role of thread priorities in GCD. Just like threads, it’s possible to use all CPU resources executing blocks on a high-priority queue and “starving” a lower-priority queue, preventing its enqueued blocks from executing at all.
You can get a reference to a global concurrent queue this way:
dispatch_queue_t defaultPriorityGlobalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);