首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在[NSRunLoop(NSRunLoop) runMode:beforeDate:]中出现奇怪的崩溃

在[NSRunLoop(NSRunLoop) runMode:beforeDate:]中出现奇怪的崩溃
EN

Stack Overflow用户
提问于 2013-07-17 14:22:50
回答 1查看 2.1K关注 0票数 0

崩溃发生在以下代码中:

代码语言:javascript
复制
void CocoaCommRequest::launchSync()
{
    launchAsync();

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

崩溃堆栈是(部分):

代码语言:javascript
复制
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)

我不能在本地复制它,但只能在生产中复制。是什么原因导致这段代码崩溃?会不会是某种记忆问题?

EN

回答 1

Stack Overflow用户

发布于 2014-02-27 19:43:20

我不知道在launchAsync();launchSync()之前发生了什么,但如果你在另一个线程中执行这些操作,你可能会遇到崩溃或意外的行为,因为NSRunLoop不是线程安全的。这里有来自苹果文档的线程安全和运行循环对象。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.

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17692551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档