Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify the priority of a custom GCD queue?

I've created a GCD queue like this:

dispatch_queue_t q = dispatch_queue_create("com.testcompany.myqueue", NULL);

When I dispatch tasks to that queue, it is way slower than simply executing the task on the main thread.

dispatch_async(q, ^(void) {
    [self performHeavyCalculationAndUpdateUI];
});

My suspicion is that the queue has a very low priority by default. How can I change the priority of this queue? Or is there something else I must do?

like image 992
Proud Member Avatar asked Apr 01 '12 14:04

Proud Member


1 Answers

Dispatch queues don't have a priority you can change.

You can change the target queue of your serial queues using the dispatch_set_target_queue functions and use the DISPATCH_QUEUE_PRIORITY_HIGH global queue. This just ensures that it will be scheduled before any other blocks enqueued on the queues with the default or low priority. Once your block starts executing it will not run faster or slower no matter what queue it was scheduled on.

Your problem most likely is the updating of your GUI, see Robert Ryans answer.

like image 125
Sven Avatar answered Sep 18 '22 21:09

Sven