从并发队列调用 dispatch_sync - 它会完全阻塞吗?

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

假设我从并发队列中调用 dispatch_sync - 它会阻塞整个队列还是只阻塞那个执行线程?

dispatch_sync 将阻塞调用者线程直到执行完成,并发队列有多个线程,因此它只会阻塞该队列中的一个线程,其他线程仍将执行。

Apple 对此是这样说的:

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