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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to