I created this thread in my iOS app, and I'd like to stop it:
dispatch_queue_t myDispatch = dispatch_queue_create("com.myqueue", DISPATCH_QUEUE_CONCURRENT);
myDispatch thread within it invokes dispatch_global_queue and dispatch_main_queue respectively to execute heavy operations and to execute graphics operations. But in response to a user action in the app can be called another function that uses another queue very similar to myDispatch. If myDispatch thread is terminated, there are no problems, but this call can also occur during the execution of myDispatch thread, and so my app crashes because both thread use the same arrays. There is a way to stop or kill a thread before its termination? I'd like to kill the thread currently running and start the new thread.
preguntado el 28 de mayo de 14 a las 14:05
If you want to cancel/stop background work you should be using
NSOperation since as far as I know once you dispatch a block with
GCD you lose control of it.
To cancel a GCD thread you have to use your own atomic flag.