iphone - GCD中的 "global queue"和 "main queue"有什么区别?

标签 iphone ios concurrency grand-central-dispatch

在其他一些方法中,有以下两种方法可以在 GCD 中获取队列:

dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_get_main_queue();

如果我没有完全错的话,“主队列”在主线程上执行,对执行 UI 工作的“回调” block 很有用。

这是否意味着“全局队列”是在后台线程上运行的队列?

最佳答案

主队列确实像你说的那样在主线程上运行。

全局队列是并发队列,来自dispatch_get_global_queue的主页:

Unlike the main queue or queues allocated with dispatch_queue_create(), the global concurrent queues schedule blocks as soon as threads become available ("non-FIFO" completion order). The global concurrent queues represent three priority bands:

       •   DISPATCH_QUEUE_PRIORITY_HIGH
       •   DISPATCH_QUEUE_PRIORITY_DEFAULT
       •   DISPATCH_QUEUE_PRIORITY_LOW

Blocks submitted to the high priority global queue will be invoked before those submitted to the default or low priority global queues. Blocks submitted to the low priority global queue will only be invoked if no blocks are pending on the default or high priority queues.

因此,它们是在可用时在后台线程上运行的队列。它们是“非先进先出”的,因此不能保证顺序。

关于iphone - GCD中的 "global queue"和 "main queue"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9602042/

相关文章:

android - 在 flutter 中传递 pushNamedandRemoveUntil 中的参数

ios - UITableViewController水平滑动分页?

javascript - 并行执行多个 promise ,但只从其中一个中检索结果

iphone - iPhone中的标签栏 Controller

iphone - AVAudioPlayer 在播放视频时无法识别设备静音按钮

ios - 无法使用 UIWebView 自动播放嵌入式 YouTube 视频吗?

c++ - 为什么这个获取和释放内存栅栏没有给出一致的值?

java - Java 中不同类型的线程安全集

iphone - 检测两个图像之间的像素碰撞/重叠

iphone - 如果设备已经在播放音乐,如何防止我的应用播放声音