NSOperationQueue question
NSOperationQueue question
- Subject: NSOperationQueue question
- From: Tim Murison <email@hidden>
- Date: Fri, 07 Aug 2009 15:06:16 -0400
- Thread-topic: NSOperationQueue question
Hi Cocoa gurus,
I'm running on Leopard 10.5.7 (and Snow Leopard, but that's a different
problem!) and have been seeing some strange behaviour with NSOperationQueue.
I know about the crash in 10.5.6 and earlier, but this doesn't seem to be
related to that crash.
The code is below and was compiled with objc-gc-only. If I run the program,
despite the setMaxConcurrentOperationCount:4, it will use 65 threads. Also
it will leak memory at ~1Mb/sec.
#import <Cocoa/Cocoa.h>
#include <libkern/OSAtomic.h>
volatile int64_t globalCounter;
@interface Operation : NSOperation
+ (Operation*) operation;
@end
@implementation Operation
+ (Operation*) operation
{
return [[Operation alloc] init];
}
- (void) main
{
OSAtomicIncrement64(&globalCounter);
}
@end
int main(int argc, char **argv)
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:4];
while (1) {
int64_t tmp;
[queue addOperation:[Operation operation]];
tmp = globalCounter;
if (tmp % 100 == 0) {
[[NSGarbageCollector defaultCollector]
collectExhaustively];
printf("Counter: %lld\n", tmp);
}
}
}
***********************************************************************
This e-mail and its attachments are confidential, legally privileged, may be subject to copyright and sent solely for the attention of the addressee(s).
Any unauthorized use or disclosure is prohibited. Statements and opinions expressed in this e-mail may not represent those of Radialpoint.
Le contenu de ce courriel est confidentiel, privilégié et peut être soumis à des droits d'auteur. Il est envoyé à l'intention exclusive de son ou de ses
destinataires. Il est interdit de l'utiliser ou de le divulguer sans autorisation. Les opinions exprimées dans le présent courriel peuvent diverger de celles de Radialpoint.
_______________________________________________
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