Is dispatch_sync (dispatch_get_global_queue (xxx), task) sync or async

As the Apple doc says, dispatch_get_global_queue () is a parallel queue, and dispatch_sync is a value meaning serial. Then are tasks processed async or sync?

+4
source share
2 answers

You are confused between what a queue is and what is asynchronous or synchronous.

A queue is an object on which you can run blocks. They can be serial or parallel. Serial means that if you place a block in the order of A, B, C, D, then they will be executed A, then B, then C, then D. In parallel, means that these blocks can be executed in a different order and, possibly, even more than one at the same time (provided that you have several cores that you need to work on, obviously).

Then in async vs sync. Async means that when you call dispatch_async, it returns immediately and the block will be queued in the queue. Synchronization means that when called, dispatch_syncit will return only after completion of the block.

, , dispatch_sync , , , , - .

+31

Apple Doc

dispatch_get_global_queue

.

dispatch_queue_t dispatch_get_global_queue (      ,     unsigned long flags);

priority . , . "dispatch_queue_priority_t". . 0. Return .

. dispatch_suspend, dispatch_resume, dispatch_set_context , .

, , .

iOS 4.0 . /queue.h

, β†’ ' .'

Async .

0

All Articles