I have an iPad application with multi-threading capabilities using GCD.
When i need to do some type of background processing, I use the following code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ -backgroundProcessing- }**
So my 2 questions are:
1) Since i have added ALL of my background processing to the same queue, and queues always dequeue FIFO, will they still be run concurrently? I’m assuming they will be, but im not sure.
2) According to Apple-Docs i already know that
The system provides each application with three concurrent dispatch
queues. These queues are global to the application and are
differentiated only by their priority level.
but, since my processing doesn’t require DISPATCH_QUEUE_PRIORITY_HIGH, DISPATCH_QUEUE_PRIORITY_LOW or DISPATCH_QUEUE_PRIORITY_BACKGROUND, is it advisable/ok/good practice/what-ever/ to put all my background processing on the DISPATCH_QUEUE_PRIORITY_DEFAULT global queue? Or should i start creating custom queues so that i can have multiple to use. And, if i do create more queues will there be any performance gain?
1) No, the global queues have a special role in this. They may execute multiple blocks concurrently on different threads. They are more or less there to have a quick way of entering background jobs if you don’t care about ordering (see [1], Blocks submitted to these global concurrent queues may be executed concurrently with respect to each other.). If you need sequential ordering, create a queue for your task. They are quite lightweight and thus not a big performance impact.
2) Default priority should be fine for normal tasks. The priorities get more interesting when creating cpu load intensive tasks or more complex queue hierarchies (as you can put queues into queues).
PS: I absolutely recommend the GCD videos from WWDC 2010 and 2011 as they give quite some insight into the more speficic parts of GCD.
[1] http://developer.apple.com/library/ios/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html