为什么我的代码崩溃了?
dispatch_async(queue_A, ^{
@synchronized(self) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self logInfo:@"queue_A"];
[pool release];
}
});
dispatch_async(queue_B, ^{
@synchronized(self) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self logInfo:@"queue_B"];
[pool release];
}
});
答案 0 :(得分:2)
根据评论中的建议,最好避免在@syncronized
内使用dispatch_async
。如果拨打[self logInfo:...]
是不安全的,那么您可能想要:
dispatch_async()
调用不会导致应用崩溃。 Mike Ash有一个good write-up of this technique。看看他的例子。我不确定logInfo在此上下文中的作用,因此您也可以重写它。
答案 1 :(得分:0)
解决了这个问题。
访问UI必须仅通过主队列