I want to create two serial queues A & B. Where queue B is a target of queue A. I want to queue up some blocks on B, and suspend it until i'm ready to execute them, however i want to continue executing blocks on queue A.
If i suspend B, will this also suspend it's target queue (queue A)?
My thinking is that i want to schedule these particular blocks (on Queue B) for execution at a later (unspecified) date however i don't want them to ever run concurrently (This involves Core Data ^_^) and i don't want to deal with semaphores. But i want Queue A to continue processing it's blocks, while B is suspended
In case that wasn't clear here's some sample code
dispatch_queue_t queueA = dispatch_queue_create("app.queue.A");
dispatch_queue_t queueB = dispatch_queue_create("app.queue.B");
dispatch_set_target_queue( queueB, queueA );
dispatch_suspend( queueB );
/*
* Add a bunch of blocks to queue B or A
* Where the ones added to A should execute immediately
*/
//Wait till blocks on queue A have finished and start up B
dispatch_resume( queueB );
dispatch_release(queueA);
dispatch_release(queueB);
A dispatch queue that is bound to the app's main thread and executes tasks serially on that thread. A dispatch queue that executes tasks concurrently using threads from the global thread pool. A dispatch queue that executes tasks serially in first-in, first-out (FIFO) order.
There are two types of dispatch queues, serial dispatch queues and concurrent dispatch queues.
A quality-of-service (QoS) class categorizes work to perform on a DispatchQueue . By specifying the quality of a task, you indicate its importance to your app. When scheduling tasks, the system prioritizes those that have higher service classes.
Yes, the dispatch queue objects, themselves, are thread-safe (i.e. you can safely dispatch to a queue from whatever thread you want), but that doesn't mean that your own code is necessarily thread-safe.
dispatch_set_target_queue(queueB, queueA);
dispatch_suspend(queueB);
queueB is suspended, but queueA is not suspended.
dispatch_set_target_queue(queueB, queueA);
dispatch_suspend(queueA);
queueA and queueB are suspended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With