DispatchQueue(label: String,qos: DispatchQoS,attributes: DispatchQueue.Attributes,autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency,target: DispatchQueue?)
我看到来自StackOverFlow的示例代码,它可以是nil,.global()或.main,这个目标参数的含义是什么?
我猜.main意味着队列将在主线程上运行,但是.nil或.global()是什么?
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,所以我无法测试.