后台线程中的SIGSEGV NSRunLoop runMode:beforeDate:

我正在使用以下模式的后台线程:

// Defined in .h-file as ivar BOOL backgroundThreadIsAlive; // .m file static NSThread *backgroundThread = nil; - (id)init { if (self = [super init]) { if (backgroundThread == nil) { backgroundThreadIsAlive = YES; backgroundThread = [[NSThread alloc] initWithTarget:self selector:@selector(threadMain:) object:nil]; [backgroundThread start]; } } return self; } - (void)threadMain:(id)data { NSRunLoop *runloop = [NSRunLoop currentRunLoop]; [runloop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; while (backgroundThreadIsAlive) { [runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } } 

我的应用程序有时会与SIGSEGV一起崩溃

 [runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 

我正在使用ARC。 崩溃是不可重现的。 刚刚find它,当潜入testing飞行,看到这是我得到的最经常崩溃。 它似乎独立于iOS版本(我支持iOS5 +)和设备types。

  • 可能有人对我有暗示,我做错了什么?
  • 有没有更好的解决scheme做后台线程? (也许使用GCD)
  • 有没有办法来重现这些问题?

感谢您的时间和指导。 🙂