Is DispatchQueue.global(qos: .userInteractive).async same as DispatchQueue.main.async

前端 未结 5 1695
一整个雨季
一整个雨季 2020-12-30 19:09

I was going through the tutorial : https://www.raywenderlich.com/148513/grand-central-dispatch-tutorial-swift-3-part-1

And came across the definition of QoS class

5条回答
  •  星月不相逢
    2020-12-30 19:31

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

    The global queues are concurrent queues and from the main page for 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.

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

提交回复
热议问题