How to stop the execution of tasks in a dispatch queue?
If I have a serial queue, how can I, from the main thread, tell it to immediately stop execution and cancel all of its tasks? There is no way to empty pending tasks from a dispatch queue without implementing non-trivial logic yourself as of iOS 9 / OS X 10.11. If you have a need to cancel a dispatch queue, you might be better off using NSOperationQueue which offers this and more. For example, here's how you "cancel" a queue: NSOperationQueue* queue = [NSOperationQueue new]; queue.maxConcurrentOperationCount = 1; // make it a serial queue ... [queue addOperationWithBlock:...]; // add operations