Le 17 déc. 08 à 10:32, Jean-Daniel Dupas a écrit :


And before you go off using NSOperationQueue, you should be aware that
it's broken on Leopard, as described in this thread:

http://www.cocoabuilder.com/archive/message/cocoa/2008/10/30/221452


We already discuss this issues, and I agree with previous post that said you misuse it:

http://www.cocoabuilder.com/archive/message/cocoa/2008/11/26/223819


I think NSOperationQueue should be used like this instead:
The process uses almost 200% of my Core 2 Duo proc and maybe i'm wrong, but I do not managed to crash it.

#import <Foundation/Foundation.h>

@interface Tester : NSObject {
  NSOperationQueue *_queue;
}

- (id)initWithQueue:(NSOperationQueue *)aQueue;
- (void)test;

@end

@implementation Tester

- (id)initWithQueue:(NSOperationQueue *)aQueue {
  if((self = [super init])) {
    _queue = [aQueue retain];
  }
  return self;
}

- (void)dealloc {
  [_queue release];
  [super dealloc];
}

- (void)test {
  NSInvocationOperation *op = [[NSInvocationOperation alloc]
initWithTarget:self selector:_cmd object:nil];
  [_queue addOperation:op];
  [op release];
}

@end

int main(int argc, char **argv)
{
  [NSAutoreleasePool new];

  NSMutableArray *testers = [NSMutableArray array];
  NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  int i;
  for(i = 0; i < 10; i++)
[testers addObject:[[[Tester alloc] initWithQueue:queue] autorelease]];

  for(Tester *tester in testers)
    [tester test];

  while(1) sleep(1000);
}


_______________________________________________

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