Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between dispatch_get_main_queue and dispatch_get_global_queue

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?

like image 705
Utkarsh S Avatar asked Dec 12 '22 13:12

Utkarsh S


1 Answers

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.

like image 117
Aaron Golden Avatar answered Dec 25 '22 22:12

Aaron Golden