iOS.GCD

1. dispatch_sync 容易引起deadlock

如果code 1-1这段代码段在main thread中执行, 就会出现deadlock.

code 1-1:

1 dispatch_queue_t queue = dispatch_get_main_queue();

2 dispatch_sync(queue, ^{NSLog(@"XiaoKL")});

如code 1-2所示的代码段同样会引起deadlock

code 1-2:

dispatch_queue_t queue = dispatch_get_main_queue(); 
dispatch_async(queue, ^{   dispatch_sync(queue, ^{NSLog(@"Hello?");});
});

 

dispatch_sync 方法应该添加到 iOS Code Review List 中.

 

 

 

你可能感兴趣的:(ios)