Why does my code crashes?
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];
}
});
You’re better off avoiding using
@syncronizedinsidedispatch_async, as suggested in the comments. If it’s not safe to call[self logInfo:...]then you might want to either:dispatch_async()calls to a resource don’t crash your app. Mike Ash has a good write-up of this technique. Check out his examples.I’m not sure what logInfo does in this context so you may be able to rewrite that as well.