PDA

View Full Version : Queues in Grand Dispatch Central




Blakeasd
Jun 1, 2011, 09:15 PM
Is a queue equivalent to a processor core? If it is what happens if you create and use more cores than the user has, can you detect the number of cores a user has in GDC?



jiminaus
Jun 1, 2011, 09:21 PM
A queue is not equal to a processor core.

The purpose of GCD is map queues to cores appropriately. Appropriately means not just the number of cores, but also taking into consideration total system workload.

Just create queues as needed and let GCD do the management. Having more queues than cores is the same as having more processes than CPUs, the operating system will manage it for you.

Don't be naive, though. Do create sequential and parallel queue intelligently for the tasks at hand. But the decision should be based around the nature of the tasks, not the user's environment.

gnasher729
Jun 2, 2011, 01:08 AM
Is a queue equivalent to a processor core? If it is what happens if you create and use more cores than the user has, can you detect the number of cores a user has in GDC?

_One_ asynchronous queue will use the exact right number of cores as needed for all tasks in the queue. How many cores depends on what other queues both in your application and in all other application are using; the OS will decide to optimise performance for everyone. Do _not_ create more queues in an attempt to use more cores, it doesn't work that way.

Blakeasd
Jun 2, 2011, 03:45 PM
What exactly is a queue then?

gnasher729
Jun 2, 2011, 04:09 PM
What exactly is a queue then?

An object responsible for executing blocks on multiple cores.

Apple spent probably lots of money for the salary of a technical writer documenting how dispatch queues work. You should make use of that money and read the documentation. If there is something you don't understand, post it here.

jiminaus
Jun 2, 2011, 05:37 PM
The Concurrent Programming Guide (http://developer.apple.com/library/mac/#documentation/General/Conceptual/ConcurrencyProgrammingGuide) is another good overview. It also talks about the higher-level NSOperationQueue, which was reimplemented on top of GCD in Mac OS X 10.6.