假设我从并发队列调用 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.
关于ios - 从并发队列调用 dispatch_sync - 它会完全阻塞吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30837356/