Among some other ways, there are these two ways to get queues in GCD
:
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_get_main_queue();
If I'm not completely wrong, the "main queue" is executing on the main thread and is good for "callback" blocks which execute UI work.
Does this mean a "global queue" is one that runs on a background thread?
Yes. You can run code like this on a device to test it:
The main queue does indeed run on the main thread like you say.
The global queues are concurrent queues and from the main page for dispatch_get_global_queue:
So, they are queues which run on background threads as and when they become available. They're "non-FIFO" so ordering is not guaranteed.
The 5 queues (4 background, 1 main) all have different thread priorities (
-[NSThread threadPriority]
) too:(tested on an iPod 4th gen and the simulator on a MacBook Pro)
Global dispatch queue :
Main dispatch queue :