• 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
Re: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:


  • Subject: Re: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 01 Oct 2011 15:44:48 -0700

On Oct 1, 2011, at 15:06 , Kyle Sluder wrote:

> NSOperationQueue backgroundQueue = /* some long-lived background queue */;
> NSOperationQueue replyQueue = [NSOperationQueue new];
> int totalResult = 0;
>
> [replyQueue setSuspended:YES];
>
> for (id foo in myFoos) {
>  [backgroundQueue addOperationWithBlock:^{
>    int result = DoSomething();
>    [replyQueue addOperationWithBlock:^{
>      totalResult += result;
>    }];
>  }];
> }
>
> [replyQueue waitUntilAllOperationsAreFinished];
>
> /* all done! */

Aren't you missing a [replyQueue setSuspended: NO] in there somewhere? And if you do that, aren't you then failing to wait for backgroundQueue to empty?

> But this falls apart if -waitUntilAllOperationsAreFinished doesn't
> look at -isSuspended, and it gets called before the first operation
> gets enqueued on the replyQueue.


I can't see anything that justifies an assumption that isSuspended has any effect on the wait. Occam's Razor says that the wait returns immediately if the queue is empty.

> I can easily work around this by enqueuing a no-op operation on
> replyQueue right after calling -setSuspended

Why not use [backgroundQueue addOperations: … waitUntilFinished: YES], then [replyQueue waitUntilAllOperationsAreFinished], and forget about isSuspended?


_______________________________________________

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: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
      • From: Stevo Brock <email@hidden>
References: 
 >NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended: (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: How to make Lion's autosaving work for my application?
  • Next by Date: Re: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
  • Previous by thread: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
  • Next by thread: Re: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
  • Index(es):
    • Date
    • Thread