-[NSOperationQueue cancelAllOperations] cleans queue, but not immediately?!
-[NSOperationQueue cancelAllOperations] cleans queue, but not immediately?!
- Subject: -[NSOperationQueue cancelAllOperations] cleans queue, but not immediately?!
- From: Jerry Krinock <email@hidden>
- Date: Wed, 31 Mar 2010 14:32:26 -0700
I execute the following code in a subclass of NSOperationQueue:
if (error) {
NSLog(@"Cancelling all operations due to error") ;
[self cancelAllOperations] ;
}
NSLog(@"#1 Remaining operations in %p:\n%@", self, [self operations]) ;
NSLog(@"#2 Remaining operations in %p:\n%@", self, [self operations]) ;
The console result:
2010-03-31 14:06:11.581 TestApp[10342:7d0f] Cancelling all operations due to error
2010-03-31 14:06:11.583 TestApp[10342:7d0f] #1 Remaining operations in 0x1a38e6a0:
(
<NSInvocationOperation: 0x1a38d740>,
SSYOperation 0x1a38d7e0 selector=saveDocument,
<NSInvocationOperation: 0x1a386510>,
SSYOperation 0x1a3a5510 selector=terminateWork,
<NSInvocationOperation: 0x1a385f20>
)
2010-03-31 14:06:11.584 TestApp[10342:7d0f] #2 Remaining operations in 0x1a38e6a0:
(
<NSInvocationOperation: 0x1a38d740>
)
So you see in NSLog #1 there are 5 operations in the queue. This is expected, because although the documentation for -cancelAllOperations is a little vague, it does not say that it *removes* any operations from the queue.
But what happens in NSLog #2? All operations are gone except the first one. All of a sudden!
Big thanks to anyone who can offer any clues on this.
Jerry Krinock
P.S. The above code is executing on a secondary thread. Is that a possible issue? NSOperationQueue is not listed as a thread-safe class in the Threading Programming Guide. But in the class documentation it says "It is safe to use a single NSOperationQueue object from multiple threads without creating additional locks to synchronize access to that object." I tried running the above code with performSelectorOnMainThread wrappers, but got a deadlock I can't explain either. (Sample shows mach_msg_trap.)
_______________________________________________
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