Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling dispatch_sync from a concurrent queue - does it block entirely?

Let's say I hypothetically call a dispatch_sync from a concurrent queue - does it block the entire queue or just that thread of execution?

like image 830
rb612 Avatar asked Sep 10 '25 23:09

rb612


1 Answers

dispatch_sync will block the caller thread until execution completes, a concurrent queue has multiple threads so it will only block one of those on that queue, the other threads will still execute.

Here is what Apple says about this:

Submits a block to a dispatch queue for synchronous execution. Unlike dispatch_async, this function does not return until the block has finished. Calling this function and targeting the current queue results in deadlock.

Unlike with dispatch_async, no retain is performed on the target queue. Because calls to this function are synchronous, it "borrows" the reference of the caller. Moreover, no Block_copy is performed on the block.

As an optimization, this function invokes the block on the current thread when possible.

Source

like image 88
cjnevin Avatar answered Sep 13 '25 11:09

cjnevin