I have just started working on iOS and have been going through Apple Reference material on GCD. dispatch_get_global _queue
returns a concurrent queue to which one can submit a block to be executed.
However, we can achieve the same using dispatch_get_main_queue
as well, right? Then, what exactly is the difference between dispatch_get_global_queue
and dispatch_get_main_queue
?
The global queue is a background queue and executes its blocks on a non-main thread. The main queue executes its blocks on the main thread.
You should put background work that does not involve changes to the user interface on the global queue, but use the main queue when the blocks make changes to the user interface. A very common pattern, for example, is to execute a "work" block on the global queue, and to have the work block itself dispatch back to the main queue to update a progress indicator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With