开发者

Does suspending a dispatch queue suspend its target queue?

开发者 https://www.devze.com 2023-03-18 07:38 出处:网络
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 exe

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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消