Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCD DISPATCH_QUEUE_SERIAL what priority is it going to run on?

I am trying to understand what priority is going to be used to run dispatch blocks that are dispatched on a custom serial queue declared as:

dispatch_queue_t queue = dispatch_queue_create("com.purposeOfQueue.queue", DISPATCH_QUEUE_SERIAL);

So, here, I am only saying that "queue" is a serial queue. But, what priority is the system going to use for this queue. I know there's HIGH, DEFAULT, LOW, BACKGROUND.

I also know I could do this:

dispatch_set_target_queue(queue, DISPATCH_QUEUE_PRIORITY_DEFAULT);

Which would make it so the queue get a DEFAULT priority.

But if I just do what I showed above?

dispatch_queue_t queue = dispatch_queue_create("com.purposeOfQueue.queue", DISPATCH_QUEUE_SERIAL);

What priority is that going to use?

like image 470
zumzum Avatar asked May 05 '14 14:05

zumzum


3 Answers

It's useful to note that from iOS 8 the creation of queues and their abilities have changed. You would use the following to get a serial queue with the lowest priority.

dispatch_queue_attr_t queueAttributes = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_BACKGROUND, 0);
self.queue = dispatch_queue_create("com.abc.myQueue", queueAttributes);
like image 200
Ricky Avatar answered Oct 25 '22 15:10

Ricky


If you don't explicitly force a priority, it will use the "default" priority. This kinda goes right to the heart of the meaning of the word "default."

like image 25
ipmcc Avatar answered Oct 25 '22 15:10

ipmcc


I believe that you can accomplish what you're looking for with:

    dispatch_set_target_queue(queue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));

or DISPATCH_QUEUE_PRIORITY_LOW as the case may be.

like image 43
David Berry Avatar answered Oct 25 '22 14:10

David Berry