【发布时间】:2012-11-27 12:35:07
【问题描述】:
我有这段从不同线程执行的代码。我找不到死锁在哪里。也许我不明白@syncronized 的工作原理
@synchronized(self) {
NSLog(@"%@", self);
NSLog(@"(%d) Aloha hermano blocked?" ,pthread_mach_thread_np(pthread_self()) );
genres = [aContext executeFetchRequest:request error:&error];
if (error != nil) {
NSLog(@"Obj list fetch error: %@", error);
exit(-1);
}
NSLog(@"(%d) Aloha hermano NO" ,pthread_mach_thread_np(pthread_self()) );
}
这是应用被锁定时的痕迹:
2012-11-27 13:28:05.141 (15143) Aloha hermano blocked?
2012-11-27 13:28:05.146 (15143) Aloha hermano NO
2012-11-27 13:28:05.152 <STBConnection_0_9: 0xc676000>
2012-11-27 13:28:05.155 (15143) Aloha hermano blocked?
2012-11-27 13:28:05.161 (15143) Aloha hermano NO
2012-11-27 13:28:05.168 <STBConnection_0_9: 0xc676000>
2012-11-27 13:28:05.171 (15143) Aloha hermano blocked?
2012-11-27 13:28:05.178 (15143) Aloha hermano NO
2012-11-27 13:28:05.185 <STBConnection_0_9: 0xc676000>
2012-11-27 13:28:05.191 (1799) Aloha hermano blocked?
如您所见,我总是在同一个对象上同步。
有什么想法吗?非常感谢
【问题讨论】:
标签: objective-c cocoa-touch core-data mutex deadlock