• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Limiting GCD concurrent queues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Limiting GCD concurrent queues


  • Subject: Limiting GCD concurrent queues
  • From: Carl Hoefs <email@hidden>
  • Date: Fri, 08 May 2015 11:51:15 -0700

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 (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Limiting GCD concurrent queues
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Subclassing NSPopUpButton
  • Next by Date: Re: Rotate a standard Cocoa control?
  • Previous by thread: Re: Subclassing NSPopUpButton
  • Next by thread: Re: Limiting GCD concurrent queues
  • Index(es):
    • Date
    • Thread