iOS GCD: Difference between any global queue and the one with background priority (DISPATCH_QUEUE_PRIORITY_BACKGROUND)?

前端 未结 2 1953
离开以前
离开以前 2021-02-01 02:17

I am reading Concurrency Programming Guide and things confuse me.

I see a lot of code invoking the following for any background task:

dispatch_get_global         


        
2条回答
  •  悲&欢浪女
    2021-02-01 03:03

    If you have many background tasks, the CPU or CPUs of your device will be shared between all of them. Most of the time that is the right thing to do. If a task takes too long to finish, you solve the problem by trying to make it more efficient.

    In very rare cases, you may have a task that takes a long time, but it is Ok to wait for it. So you give it BACKGROUND priority. If there is any work to do at NORMAL priority, that work will be done first, and only when there is a spare CPU doing nothing else, the BACKGROUND task will be performed. And there is the queue with HIGH priority; tasks in that queue will be executed first; you would do that if one specific task needs to be finished as quick as possible even if it means that other tasks are delayed.

    From a point of view of your programming logic, all three queues are identical. It just affects which tasks the OS tries to finish first, and which it doesn't care about that much.

提交回复
热议问题