[libdispatch-dev] Queue size

Jordan K. Hubbard jkh at apple.com
Tue Sep 28 16:10:39 PDT 2010


I think the essential answer to his question, reading between the lines, is that if you want to limit the number of concurrent operations to n, then the proper thing to do is submit them to a concurrent queue and then use a counting semaphore to implement the behavior you want (2 at a time, 3 at a time, whatever).  Queues cannot have variable widths - it's either 1 or "infinite".  That idea was considered but ultimately dropped given that it only made submitting things to queues even less deterministic in terms of where/how they would run, and there is already a way (again, semaphores) to get that behavior, so this would have only added complexity to all queues for little overall gain.  Should someone propose a truly compelling scenario that changes the whole cost/benefit ratio, can certainly revisit the idea.

- Jordan

On Sep 28, 2010, at 3:37 PM, David Leimbach wrote:

> Your question makes me feel like I should try to clarify my understanding of queues in libdispatch.  Here goes:
> 
> There's only one concurrent queue in which the "tasks" or blocks/function pointers can be run in simultaneously as far as I can tell.  Every other queue is serial, and the queues themselves may run in parallel and with different priorities.
> 
> This is why it makes sense to think of a queue as a context, and that you're serializing accesses to that context by enqueueing accesses and updates to that queue.  The programmer's benefit in this situation is that they can isolate queue contextual data in a nice way without thinking about mutexes or semaphores etc, and the queues are really pretty inexpensive as can be seen in the game of life demo sample code in libdispatch which I think is using a queue per discrete element.
> 
> Dave
> 
> On Tue, Sep 28, 2010 at 1:30 PM, Danilo Egea <daniloegea at yahoo.com.br> wrote:
> First, sorry my english...
> 
> Are possible define the queue size in GCD?
> 
> Example: Define the max. number of task run simultaneous in a queue.
> 
> -- 
> Danilo Egêa Gondolfo
> Email/MSN - daniloegea at yahoo.com.br
> Skype - daniloegea
> Twitter - http://twitter.com/daniloegea
> Blog - http://daniloegea.wordpress.com
> 
> __________________________________________________
> Fale com seus amigos  de graça com o novo Yahoo! Messenger http://br.messenger.yahoo.com/ 
> _______________________________________________
> libdispatch-dev mailing list
> libdispatch-dev at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/libdispatch-dev
> 
> _______________________________________________
> libdispatch-dev mailing list
> libdispatch-dev at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/libdispatch-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/libdispatch-dev/attachments/20100928/83bab8e8/attachment.html>


More information about the libdispatch-dev mailing list