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

标签 ios objective-c multithreading swift grand-central-dispatch

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

相关文章:

ios - 由于 IBOutlets 而发生 SIGABRT 异常

ios - 检查 iOS 中的应用方向(不是设备方向)

c# - 使用 Mono API 启动新线程和打开对话框时出错

java - "Build Automatically"Swing 函数

c# - 我可以使用 Json.net 在一次操作中将嵌套属性序列化到我的类吗?

android - 从移动应用程序中检测成功的 facebook 的最佳方法是什么?

ios - 调用函数时无法隐藏 iOS 工具栏

iphone - NSManagedObject 不兼容的指针类型警告

iOS - 如何使对象一次只能拖动到一个方向

ios - 如何在 Cocoa Touch 中任意两个 ViewController 之间转换?