Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the main Grand Central Dispatch queue serial or concurrent?

Suppose I call dispatch_async() three times in order:

dispatch_async(dispatch_get_main_queue(),
         ^{
             [self doOne];
});

// some code here

dispatch_async(dispatch_get_main_queue(),
         ^{
             [self doTwo];
});

// more code here

dispatch_async(dispatch_get_main_queue(),
         ^{
             [self doThree];
});

Will this always be executed like

[self doOne], [self doTwo], then [self doThree], or is the order is guaranteed?

In this case, the question probably is if the main queue is serial or concurrent.

like image 267
Duck Avatar asked May 18 '13 19:05

Duck


1 Answers

From the documentation:

dispatch_get_main_queue

Returns the serial dispatch queue associated with the application’s main thread.

so the main queue is a serial queue, and [self doOne], [self doTwo], [self doThree] are executed sequentially in that order.

like image 85
Martin R Avatar answered Sep 30 '22 17:09

Martin R