2013-07-17 74 views
0

的碰撞發生在以下代碼:具有在怪異崩潰[NSRunLoop(NSRunLoop)runMode:beforeDate:]

void CocoaCommRequest::launchSync() 
{ 
    launchAsync(); 

    while (![_delegate finished]) 
    { 
     [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 
    } 
} 

碰撞堆棧是(部分):

Exception Type: SIGSEGV 
Exception Codes: SEGV_ACCERR at 0x8 
Crashed Thread: 0 
Thread 0 Crashed: 

0 0x3aa9b5d0 objc_msgSend + 15 
1 0x32d7a8f7 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 
2 0x32d7a15d __CFRunLoopDoSources0 + 213 
3 0x32d78f2f __CFRunLoopRun + 647 
4 0x32cec23d CFRunLoopRunSpecific + 356 
5 0x32cec0c9 CFRunLoopRunInMode + 104 
6 0x336105c3 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 255 
7 0x000978f9 CocoaCommRequest::launchSync() (CocoaCommRequest.mm:46) 

我所能不是在本地複製它,而只在生產中複製。 什麼使這段代碼崩潰?它可能是某種內存問題?

+0

嗯。到目前爲止沒有答案,你有沒有得到這個地方? –

+0

對我來說,似乎有一個類似的問題:http://stackoverflow.com/questions/18760334/sigsegv-in-background-thread-nsrunloop-runmodebeforedate 埃裏克,斯科特,有什麼想法嗎? :| –

回答

1

我不知道launchAsync();launchSync()之前會發生什麼,但是如果您在另一個線程中執行這些操作,您可能會因爲NSRunLoop不是線程安全的而在其他線程中執行這些操作。有Apple Apple的[線程安全和運行循環對象]。 1

The functions in Core Foundation are generally thread-safe and can be called from any thread. If you are performing operations that alter the configuration of the run loop, however, it is still good practice to do so from the thread that owns the run loop whenever possible. The Cocoa NSRunLoop class is not as inherently thread safe as its Core Foundation counterpart. If you are using the NSRunLoop class to modify your run loop, you should do so only from the same thread that owns that run loop. Adding an input source or timer to a run loop belonging to a different thread could cause your code to crash or behave in an unexpected way.