I have a set of tasks that are done repeatedly and instead of creating a new thread each time this user-invoked task needs to be performed, I'd like to use a thread-pool.
In the typical flow to create a new thread, you have to setup an auto-release pool each time the thread entry point is invoked. It seems that the performance for this operation may be trivial according to http://www.mikeash.com/?page=pyblog/autorelease-is-fast.html but what I want to do is avoid the costs associated with setting up and tearing down a lots of these threads during the execution of my app. In other frameworks/languages, I've just retrieved an idle thread and have it do the work. When it's done with the work, the thread gets returned back to the pool.
I don't see any threadpool objects in the iPhone SDK just NSThread. What's a good way to do this?
How I'm setting up my thread:
// create thread using supplied entry point
[NSThread detachNewThreadSelector:@selector(myMethod)
toTarget:self
withObject:nil];
// thread entry-point
- (void)myMethod {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
*** code that should be run in the new thread goes here ***
[pool release];
}