NSThread implements a method -(void)cancel
that sets state information in the receiving thread to indicate, it should exit. The receiving background thread should - if behaving properly - regulary check whether it is cancelled using -(BOOL)isCancelled
.
This way the receiver has a chance to clean up it's acquired resources in a proper way.
Looking into the Java language thread semantic, this apparatus works quite the same way. Javas Thread implements two methods void Thread.interrupt()
and boolean Thread.isInterrupted()
.
In case long running background operations do not react to an attempt to -cancel
them, i would see this as an serious problem and file a bug report / change request.
You may wait on the termination of the background thread by regulary calling either -(BOOL)isFinished
or -(BOOL)isExecuting
on the background NSThread
. Unfortunately the NSDidBecomeSingleThreadedNotification
is not supported on the iPhone plattform.