主進(jìn)程中添加任務(wù)到GCD的main?queue會(huì)卡死,而如果用生成的queue卻正常運(yùn)行:
dispatch_queue_t?serialQueue?=?dispatch_queue_create("squeue",NULL);
//????dispatch_queue_t?mainQueue?=?dispatch_get_main_queue();
NSLog(@"Main?Queue-->%@",?dispatch_get_main_queue());
dispatch_sync(serialQueue,?^{//如果用mainQueue就卡死
NSLog(@"Task?1-->%@",?[NSThreadcurrentThread]);
});
在main()中執(zhí)行沒問題,如果dispatch_sync改用mainQueue的話就卡死了。
這個(gè)是最典型的互相等待導(dǎo)致鎖死呀。
調(diào)用的dispatch_sync函數(shù)一直得不到返回,main?queue被阻塞,而我們的block又需要等待main?queue來執(zhí)行它,死鎖愉快的產(chǎn)生了。

Everything?in?your?program?runs?on?the?main?queue?except?for?code?that?you?explicitly?dispatch?onto?another?queue.?Code?on?the?main?queue?will?always?run?on?the?main?thread.?Code?dispatched?on?another?queue?may?or?may?not?run?on?the?main?thread.
當(dāng)然也可能是自己太菜,連所有語句都是運(yùn)行在主隊(duì)列上這種大家都普遍默認(rèn)的常識(shí)都不懂,所以才會(huì)大費(fèi)周章的解釋死鎖現(xiàn)象。因?yàn)橐郧坝胏,不太有iOS主隊(duì)列的概念。