在其他一些方法中,有以下两种方法可以在 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/