Open dgccom opened 7 years ago
- (void)setProgress:(CGFloat)progress
{
dispatch_queue_t queue = dispatch_get_main_queue();
NSLog(@"演示死锁");
dispatch_sync(queue, ^{
//如果进入死锁 这里的log是不会被执行的 并且程序崩溃
NSLog(@"死锁了...%@",[NSThread currentThread]);
});
NSLog(@"演示死锁结束");
NSThread *currentThread = [NSThread currentThread];
NSLog(@"currentThread 打印线程---%@",currentThread);
_progress = progress;
[self setNeedsDisplay];
if (progress >= 1) {
dispatch_sync(dispatch_get_main_queue(), ^{
NSThread *mainThread = [NSThread currentThread];
NSLog(@"mainThead 打印线程---%@",mainThread);
[self removeFromSuperview];
});
}
}
如果打印结果图片挂了 就自己打开这个连接看结果和解释: http://wx1.sinaimg.cn/mw690/7ef5f86agy1fjrac336uhj21fu0sswqe.jpg
打印结果:
2017-09-21 16:42:56.213855+0800 jinxin[17290:8624928] 演示死锁
2017-09-21 16:42:56.213900+0800 jinxin[17290:8624767] 死锁了...<NSThread: 0x174068880>{number = 1, name = main}
2017-09-21 16:42:56.213944+0800 jinxin[17290:8624928] 演示死锁结束
2017-09-21 16:42:56.213965+0800 jinxin[17290:8624928] currentThread 打印线程---<NSThread: 0x174670b00>{number = 8, name = (null)}
2017-09-21 16:42:56.214003+0800 jinxin[17290:8624767] mainThead 打印线程---<NSThread: 0x174068880>{number = 1, name = main}
有代码死锁