@
lee0100317 的确是这样, 他没搞清楚 dispatch_queue 和执行的 Thread 其实是分开的.
先回答为什么没有死锁问题 dispatch_sync 文档的 discussion 里面有这么一句 "Calling this function and targeting the current queue results in deadlock." 所以死锁问题有正确答案了.
https://developer.apple.com/documentation/dispatch/1452870-dispatch_sync然后解释为什么是主线程 还是👆的文档里面的 "As a performance optimization, this function executes blocks on the current thread whenever possible, with one obvious exception."
现在有 新建的 queue 和 main dispatch queue, 都是任务, Main_Thread 是(执行)资源. 在 Main_thread 调用 dispatch_sync, 把 block 任务加入 新 queue, 然后按照"this function executes blocks on the current thread whenever possible" 新 queue 拥有了主线程的执行资源, 进行执行, 然后返回继续 main dispatch queue .
所以 main dispatch queue 是持有了什么东西造成了死锁呢?