How to free blocks stack of my serial queue? I've put some blocks on asynchronous execution into queue and in some point I want to fully free this queue to be empty. I'm using low level dispatch_queue_t
. Is it possible? Thanks.
Asked
Active
Viewed 336 times
1

user500
- 4,519
- 6
- 43
- 56
-
Are you trying to cancel currently executing blocks? That basically cannot be done by `dispatch_queue` directly, you'll either need to use a higher-level construct like `NSOperationQueue` or you'll need to add a quick-exit cancel to your dispatch queue execution. – gaige Mar 19 '13 at 11:03
-
I don't think "currently executing blocks" is proper as we are talking about FIFO queue. Let's say there could be currently executing block in point when I want to free the queue. I understand, if currently executing block can't by canceled, so if this block will finish execution, it will be fine. But I want to cancel remaining blocks that are stacked for execution. What do you mean by quick-exit cancel? – user500 Mar 19 '13 at 11:16
-
There is no cancellation method whatsoever in dispatch queues. So, all blocks will execute, and at some point in time will become currently-executing. There is no flush mechanism for dispatch queues. – gaige Mar 19 '13 at 11:29
1 Answers
0
What kind of queue are you using??
Is it NSOperationQueue??
Then -[NSOperationQueue cancelAllOperations]
should do the job.

Xcoder
- 1,762
- 13
- 17
-
Sorry for not being more specific. I'm using low level `dispatch_queue_t`. – user500 Mar 19 '13 at 09:41
-
From other sources I got the following. Please read this. "NSOperationQueue gives you a lot more control over how your operations are executed. You can define dependencies between individual operations for example, which isn't possible with plain GCD queues. It is also possible to cancel operations that have been enqueued in an NSOperationQueue (as far as the operations support it). When you enqueue a block in a GCD dispatch queue, it will definitely be executed at some point." – Xcoder Mar 19 '13 at 09:45
-
Yes, but I need serial FIFO queue and `NSOperationQueue` does not work like that. – user500 Mar 19 '13 at 09:53
-
Please refer http://stackoverflow.com/questions/10948804/nsoperationqueue-serial-fifo-queue – Xcoder Mar 19 '13 at 10:15