• 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: Canceling NSInvocationOperation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Canceling NSInvocationOperation


  • Subject: Re: Canceling NSInvocationOperation
  • From: James Montgomerie <email@hidden>
  • Date: Mon, 14 Feb 2011 17:18:41 +0000

I think you are exposing yourself to a race condition here, even if you did get this to work - imagine:

> ---------------------------
> // Some Code:
> - (void)myOperationInController;
> {
>    // Do stuff
>    if (![self isCancelled])

<-- main thread sets isCancelled to YES -->

>        [self performSelectorOnMainThread...]
> }


Presuming you're not saying "waitUntilDone:YES", a similar thing could also happen if the main thread sets isCancelled after your  myOperationInController method has returned, but before the queued method call created by the performSelectorOnMainThread... on the main thread's run loop is actually executed.

Since you're going to have to deal with the fact that supposedly cancelled operations may initiate the performSelectorOnMainThread's callback (to fix this edge case), a simpler approach to the whole problem might be to /always/ performSelector..., even if the operation is cancelled, and deal with (probably just ignore) 'cancelled' operations in the callback itself.

Jamie.

_______________________________________________

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: Canceling NSInvocationOperation
      • From: Chase Latta <email@hidden>
References: 
 >Canceling NSInvocationOperation (From: Chase Latta <email@hidden>)

  • Prev by Date: Re: Canceling NSInvocationOperation
  • Next by Date: Using NSTerminateLater with a Status Item
  • Previous by thread: Re: Canceling NSInvocationOperation
  • Next by thread: Re: Canceling NSInvocationOperation
  • Index(es):
    • Date
    • Thread