Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set priority for custom created serial asynchronous queue

How can I set high priority to a custom created serial asynchronous queue using GCD's?

I had a look at this Q&A where suggestion is made to make use of dispatch_set_target_queue() & Pass High Priority Queue (DISPATCH_QUEUE_PRIORITY_HIGH) which is a Concurrent Queue to custom serial asynchronous queue.

My understanding is that this will make all the tasks on the Serial Queue execute concurrently. Is my understanding correct? If so, what is an alternate solution?

like image 843
Pranav Jaiswal Avatar asked Oct 03 '14 16:10

Pranav Jaiswal


2 Answers

Prior to iOS 8 setting the target queue to a high priority queue is how you would achieve this. Your queue will remain serial even though the target queue is concurrent.

As of version 8.0 there is another way to do this:

dispatch_queue_attr_t queueAttrs = dispatch_queue_attr_make_with_qos_class(
    DISPATCH_QUEUE_SERIAL,
    QOS_CLASS_USER_INITIATED /* Same as DISPATCH_QUEUE_PRIORITY_HIGH */, 
    0
);

dispatch_queue_t queue = dispatch_queue_create("myqueue",queueAttrs);
like image 149
aLevelOfIndirection Avatar answered Nov 12 '22 00:11

aLevelOfIndirection


Your queue will still be serial. It will just be performing its tasks, one at a time, in one slot of the high priority, global, concurrent background queue. Once created, a serial queue cannot be "made concurrent" by any means.

Similarly, if you create a concurrent queue and you set it to target a serial queue, it effectively becomes serial.

This is all covered in this man page.

like image 25
ipmcc Avatar answered Nov 12 '22 00:11

ipmcc