以下代码创建了一个具有主线程超时和被杀死的应用程序的场景 . 我不明白为什么 .

此方法由主线程调用,并且根据堆栈跟踪,此调用不是同步的(它直接从main.m触发) . 然而,为什么需要20秒才能完成?只有在计时器触发后,此事件才会出现吗?

[fooObj performSelector:@selector(populate) withObject:nil afterDelay:2];

崩溃日志:

经过的总CPU时间(秒):20.060(用户20.060,系统0.000),100%CPU经过的应用程序CPU时间(秒):19.438,97%CPU线程0名称:调度队列:com.apple.main-thread线程0 :0 CoreFoundation 0x3ad408b4 CFArrayGetFirstIndexOfValue 348 1 CoreFoundation 0x3ad46e88 CFRunLoopRemoveTimer 224 2 CoreFoundation 0x3ad46d00 CFRunLoopTimerInvalidate 324 3 MyApp 0x00034b94 - [容器清除](Container.m:147)4 MyApp 0x000348aa - [容器填充](Container.m:77)5 MyApp 0x00034f62 - [BaseContainer填入](BaseContainer.m:75)6基金会0x35bfaa6a __NSFireDelayedPerform 446 7的CoreFoundation 0x3add45dc CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION 12 8的CoreFoundation 0x3add428c __CFRunLoopDoTimer 268 9的CoreFoundation 0x3add2efc __CFRunLoopRun 1228 10 10的CoreFoundation 0x3ad45eb8 CFRunLoopRunSpecific 352 11的CoreFoundation 0x3ad45d44 CFRunLoopRunInMode 100个12 GraphicsServices 0x391132e6 GSEventRunModal 70 13的UIKit 0x33f852f4 UIApplicationMai n 1116 14 MyApp 0x000029c6 main(main.m:14)

出于同样的原因,这是另一次崩溃:MT超时 . (似乎从日志中,线程0正在等待它自己的互斥锁被释放 . 死锁或误读日志?)

经过的总CPU时间(秒):20.060(用户20.060,系统0.000),100%CPU经过的应用CPU时间(秒):18.175,91%CPU

线程0名称:调度队列:com.apple.main-thread线程0:

0 libsystem_kernel.dylib 0x32af50fc __psynch_mutexwait 24 1 libsystem_c.dylib 0x35e56124 388的pthread_mutex_lock 2的CoreFoundation 0x3ad46df8 CFRunLoopRemoveTimer 80 3基础0x35bfaa20 __NSFireDelayedPerform 372 4的CoreFoundation 0x3add45dc CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION 12 5的CoreFoundation 0x3add428c __CFRunLoopDoTimer 268 6的CoreFoundation 0x3add2efc __CFRunLoopRun 1228 7的CoreFoundation 0x3ad45eb8 CFRunLoopRunSpecific 352 8的CoreFoundation 0x3ad45d44 CFRunLoopRunInMode 100 9 GraphicsServices 0x391132e6 GSEventRunModal 70 10 UIKit 0x33f852f4 UIApplicationMain 1116 11空间之心0x000029c6 main(main.m:14)12空间之心0x00002980 0x1000 6528

编辑:添加了清晰和填充的impl . 如您所见,没有阻止呼叫 .

- (void)clear
{
    self.m_msdData = [NSMutableData dataWithLength:0];
    self.m_maItems = [NSMutableArray arrayWithCapacity:0];
    self.m_mdItems = [NSMutableDictionary dictionaryWithCapacity:0];
    [m_timer invalidate];
    self.m_timer = nil;
    self.m_nsUrlConnection = nil;

    // zz Don't change the property state, in case an observer is already listening.
    m_nState = CS_UNPOPULATED;
}


- (CONTAINER_STATE)populate
{
    [self clear];

    self.m_timer = [NSTimer scheduledTimerWithTimeInterval:TIME_OUT_SEC 
                                target:self 
                                selector:@selector(timeout) 
                                userInfo:nil 
                                repeats:NO];

    self.m_nState = CS_POPULATING;

    return CS_POPULATING;
}