gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:52:56 25 4
gpt4 key购买 nike

假设我从并发队列调用 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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com