5 sec later,i used [newThread cancel] in main thread to stop the sub-thread,but it didnt work,
Method MyThread: in newThread still working
so,whats the correct answer to stop newThread,THX
A:
cancal method
only informs the thread that it is cancelled (as you mentioned changes theisCancelled to YES.
It's then the responsibility of the thread itself to check this and exit. For example, in your MyThread: method
you could do this:
// At some checkpointif([[NSThread currentThread] isCancelled]){/* do some clean up here */[NSThread exit];}
You should do this check periodically, and exit from within the thread as shown; otherwise the canceldoesn't
have any effect.
@None: It means that "cancelling" a thread doesn't do what you think. When you cancel a thread, it causes isCancelled to
return YES.
The thread should then stop executing. It doesn't force the thread to immediately stop execution, though — that would be troublesome if it had any resources open