views:

23

answers:

1

I am having a confusion with threads.

Suppose I start a thread in a ViewController which is doing some heavy processing. If I pop the viewController while the thread is still in execution will the thread stop executing or whether it will continue its execution.

+1  A: 

It will continue to run until it finishes or you make it stop. So you should either kill that thread at an appropriate point, or make sure that the thread doesn't access any stale objects.

Eiko
How we can kill that thread?
tek3
@tek3 How did you start it?
kubi
@kubi : I start it like [NSThread detachNewThreadSelector:@selector(doSomeProcessing) toTarget:self withObject:nil];
tek3
You should be able to stop the thread by setting a flag on your main thread and periodically polling the flag in your `doSomeProcessing` method.
kubi