【发布时间】:2013-10-11 10:02:59
【问题描述】:
我知道您可能会觉得这是一个奇怪的问题,但我只是在学习 GCD,我想完全了解它的所有方面。所以这里是:
是否有任何理由在 CURRENT QUEUE 上调度任务 SYNC?
例如:
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(...);
dispatch_async(concurrentQueue, ^{
//this is work task 0
//first do something here, then suddenly:
dispatch_sync(concurrentQueue, ^{
//work task 1
});
//continue work task 0
});
我了解一件事:如果我使用 serial 队列而不是 concurrentQueue,那么我会在该串行队列上陷入死锁,因为 work task 1 在 work task 0 完成之前无法启动(因为保证执行顺序的串行队列),同时work task 0 无法继续执行,因为它等待 SYNC dispath 函数返回(如果我错了请纠正我,那会让我总菜鸟)。
所以回到最初的想法,上面的代码和相同的代码之间有什么区别,而不是直接调用dispatch_sync 函数,而是直接编写work task 1 代码?
【问题讨论】:
标签: ios multithreading concurrency grand-central-dispatch