dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sleep(3);
NSLog(@"dispatch_sync(dispatch_get_global_queue 同步 全局并发队列");
});
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"dispatch_sync在等待block语句执行完成,而block语句需要在主线程里执行,所以dispatch_sync如果在主线程调用就会造成死锁");
NSLog(@"dispatch_sync是同步的,本身就会阻塞当前线程,也即主线程。而又往主线程里塞进去一个block,所以就会发生死锁");
});
dispatch_async(dispatch_get_main_queue(), ^{
sleep(3);
NSLog(@"dispatch_async(dispatch_get_main_queue() 异步 主队列");
});
NSLog(@"1234");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sleep(10);
NSLog(@" dispatch_async(dispatch_get_global_queue 异步 全局并发队列");
});
NSLog(@"52431");