• 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: NSInvocationOperations mysteriously whacked out of NSOperationQueue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSInvocationOperations mysteriously whacked out of NSOperationQueue


  • Subject: Re: NSInvocationOperations mysteriously whacked out of NSOperationQueue
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 14 Sep 2011 05:20:42 -0700

On 2011 Aug 24, at 23:30, Ken Thomases wrote:

> At a guess, the NSOperationQueue may be dequeuing operations using something like -[NSMutableArray removeObject:] instead of -[NSMutableArray removeObjectIdenticalTo:].  Thus, it is depending on -isEqual:.  I further guess that NSInvocationOperation objects with identical targets and selectors compare equal.
>
> Definitely sounds like a bug.
>
> You could test by a) subclassing NSInvocationOperation to change its equality semantic and seeing if the problem goes away, and b) seeing if you can reproduce with a custom NSOperation subclass which implements equality based on value and not identity.

Well, since I'd already moved on from there, I tried to reproduce this in a little demo project.  But the demo behaves as expected.  There must have been something else hiding in my code that was triggering the problem, but not worth me investigating further at this point.

Here is the demo project.  It prints "Hello, World" three times, as expected.



#import <Foundation/Foundation.h>

@interface Hellower : NSObject {
}

+ (void)hello ;

@end

@implementation Hellower

+ (void)hello {
    NSLog(@"Hello World") ;
    sleep(1) ;
}


@end


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init] ;

    NSRunLoop* runLoop = [NSRunLoop currentRunLoop] ;
    NSOperationQueue* queue = [[NSOperationQueue alloc] init] ;

    NSOperation* priorOp = nil ;
    for (NSInteger i=0; i<6; i++) {
        NSOperation* op ;

        if (i%2 == 0) {
            op = [[NSOperation alloc] init] ;
        }
        else {
            op = [[NSInvocationOperation alloc] initWithTarget:[Hellower class]
                                                      selector:@selector(hello)
                                                        object:nil] ;
        }

        if (priorOp) {
            [op addDependency:priorOp] ;
        }
        priorOp = op ;
        [queue addOperation:op] ;

        [op release] ;
    }

    [runLoop run] ;
    [queue release] ;
    [pool drain] ;
    return 0 ;
}

_______________________________________________

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

  • Prev by Date: Re: Responder-Chain question.
  • Next by Date: Implementing a "Synchronous Channel" with dispatch
  • Previous by thread: Cocoaheads Lake Forest Meeting tomorrow, Wed. Sep. 14
  • Next by thread: Implementing a "Synchronous Channel" with dispatch
  • Index(es):
    • Date
    • Thread