我得到这个代码的行为有些疑惑:dispatch_sync叫成dispatch_async呼叫
dispatch_async(queue, ^{
sleep(2);
NSLog(@"step1");
dispatch_sync(queue, ^{
sleep(3);
NSLog(@"step 2");
});
NSLog(@"step 3");
});
从这些行我希望获得尽可能输出step1 -> step3 -> step2
但我只获得step1
。
如果我使用dispatch_async更改dispatch_sync,它的工作方式与预期的一样,dispatch_sync调用dispatch_async调用会产生这种问题吗?
编辑答案后----------------
此情况下创建一个僵局:
您可以检查接受的答案有这种情况的解释并检查此链接的文档http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/dispatch_async.3.html