OS X 10.10.3  Xcode 6.3.1

I need to limit a GCD concurrent queue to a specific number of concurrently 
executing tasks (less than the number of cores available). The only way I can 
get this to work is by adding "external plumbing" in the form of semaphores to 
the dispatch invocation:

  dispatch_queue_t gcdConcQueue = dispatch_queue_create("GCDProcQueue", 
DISPATCH_QUEUE_CONCURRENT);
  dispatch_semaphore_t concLimitSem = dispatch_semaphore_create(16);
    . . .
  dispatch_async(gcdConcQueue, ^{
                dispatch_semaphore_wait(concLimitSem, DISPATCH_TIME_FOREVER);
                    // Concurrent DB access, etc . . .
                dispatch_semaphore_signal(concLimitSem);
            });

I was hoping an API like the following might be lurking around somewhere:

    gcdConcQueue = dispatch_queue_create("GCDConcQueue", 
DISPATCH_QUEUE_CONCURRENT, 16);

in which the queue manages itself behind the scenes. Is the semaphore approach 
currently the (only) way to do this? Would this make sense as an API 
enhancement? Am I overlooking something obvious?

-Carl


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to