For "fire and forget", try [self performSelectorInBackground:@selector(heavyStuff) withObject:nil]
. If you have more than one operation like this, you may want to check out NSOperation
and its subclass NSInvocationOperation
. NSOperationQueue
managed thread pooling, number of concurrently executing operations and includes notifications or blocking methods to tell you when all operations complete:
[self myFoo];
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(heavyStuff) object:nil];
[operationQueue addOperation:operation];
[operation release];
[self myBar];
...
[operationQueue waitUntilAllOperationsAreFinished]; //if you need to block until operations are finished
At a lower level, you can use use -[NSThread detachNewThreadSelector:@selector(heavyStuff) toTarget:self withObject:nil]
.