“全局队列”的区别是什么,和“主队列”在GCD? [英] What's the difference between the "global queue" and the "main queue" in GCD?

查看:320
本文介绍了“全局队列”的区别是什么,和“主队列”在GCD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Among some other ways, there are these two ways to get queues in GCD:

dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_get_main_queue();

如果我没有完全错误,主队列正在主线程上执行,

If I'm not completely wrong, the "main queue" is executing on the main thread and is good for "callback" blocks which execute UI work.

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

Does this mean a "global queue" is one that runs on a background thread?

推荐答案

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

The main queue does indeed run on the main thread like you say.

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

The global queues are concurrent queues and from the main page for dispatch_get_global_queue:


与使用
dispatch_queue_create()分配的主队列不同,全局并发队列
在线程变为可用时调度块(非FIFO完成顺序)。全局并发
队列表示三个优先级队列:

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.



p>因此,它们是在后台线程上运行的队列,当它们可用时。它们是非FIFO,因此无法保证排序。

So, they are queues which run on background threads as and when they become available. They're "non-FIFO" so ordering is not guaranteed.

这篇关于“全局队列”的区别是什么,和“主队列”在GCD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆