我想创建两个串行队列A& B.队列B是队列A的目标.我想在B上排队一些块,并暂停它直到我准备执行它们,但是我想继续在队列A上执行块.
如果我暂停B,这还会暂停它的目标队列(队列A)吗?
我的想法是,我想安排这些特定的块(在队列B上)在稍后(未指定的)日期执行但是我不希望它们同时运行(这涉及核心数据^ _ ^)而我不这样做想要处理信号量.但我希望队列A继续处理它的块,而B则被暂停
如果不清楚这里是一些示例代码
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被挂起,但queueA未被挂起.
dispatch_set_target_queue(queueB,queueA); dispatch_suspend(queueA);
queueA和queueB被挂起.