views:

54

answers:

2

i.e., I am creating a new thread like this:

[NSThread detachNewThreadSelector:@selector(doSomething) toTarget:self withObject:nil];

will this automatically make my app multithreaded or must I do some extra work somewhere?

+2  A: 

This will make your app multithreaded, but you need to be really careful. If you don't manage your threads correctly, you're going to run into a lot of trouble further down the road.

You should look into NSOperationQueue and NSOperation and see how they work.

Together you can build a multithreaded app, that abstracts the concurrency into queues and separate operations that run on those queues.

Also as an aside, any methods that you do spawn onto a new thread will need to be wrapped inside an autorelease pool. New threads don't have their own autorelease pool by default, so you need to set up your own.

Jasarien
+2  A: 

It's automatic. In the docs for that method:

If this thread is the first thread detached in the application, this method posts the NSWillBecomeMultiThreadedNotification with object nil to the default notification center.

GUI Cocoa apps are pretty much always multithreaded these days.

Ken