swift – DispatchQueue中的目标参数

Swift 3中,创建了一个dispatchQueue实例:
dispatchQueue(label: String,qos: dispatchQoS,attributes: dispatchQueue.Attributes,autoreleaseFrequency: dispatchQueue.AutoreleaseFrequency,target: dispatchQueue?)

我看到来自StackOverFlow的示例代码,它可以是nil,.global()或.main,这个目标参数的含义是什么?

我猜.main意味着队列将在主线程上运行,但是.nil或.global()是什么?

Swift没有文档,所以我回到了GCD的旧文档.我发现的最接近函数 dispatch_set_target_queue

An object’s target queue is responsible for processing the object. The target queue determines the queue on which the object’s finalizer is invoked. In addition,modifying the target queue of some objects changes their behavior:

dispatch queues:

A dispatch queue’s priority is inherited from its target queue. Use the dispatch_get_global_queue function to obtain a suitable target queue of the desired priority.

If you submit a block to a serial queue,and the serial queue’s target queue is a different serial queue,that block is not invoked concurrently with blocks submitted to the target queue or to any other queue with that same target queue.

所以看起来目标队列做了两件事:

>为新队列提供priorty
>执行队列中所有对象的终结器(deinit)

在行之间读取,队列和目标队列之间存在一些同步.我目前没有Xcode,所以我无法测试.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...