Objective c NSThread detachNewThreadSelector在主线程上执行
少数客户使用以下挂起日志签名从我的OS X应用程序中获得挂起:Objective c NSThread detachNewThreadSelector在主线程上执行,objective-c,multithreading,cocoa,Objective C,Multithreading,Cocoa,少数客户使用以下挂起日志签名从我的OS X应用程序中获得挂起: 26 ??? [0x7fff93e87fc9] 26 ??? [0x7fff93e8372a] 26 ??? [0x7fff93e83899] 26 __NSThread__main__ + 1318 (Foundation) [0x7fff8be96dfb] 26 -[AppController startClean] + 1319 (Housekeeper) [0x100007742] 1
26 ??? [0x7fff93e87fc9]
26 ??? [0x7fff93e8372a]
26 ??? [0x7fff93e83899]
26 __NSThread__main__ + 1318 (Foundation) [0x7fff8be96dfb]
26 -[AppController startClean] + 1319 (Housekeeper) [0x100007742]
13 -[AppController trashMediaCache:] + 435 (Housekeeper) [0x100010e7a]
13 +[MYFileManager trashFilesOfType:inFolder:] + 482 (Housekeeper) [0x100022e2a]
13 +[MYFileManager trashFile:] + 22 (Housekeeper) [0x1000227f7]
12 +[MYFileManager trashFile:shouldAuth:] + 226 (Housekeeper) [0x1000228de]
12 -[NSWorkspace performFileOperation:source:destination:files:tag:] + 319 (AppKit) [0x7fff8aa72bbb]
12 -[NSWorkspace _fileOperation:source:destination:files:] + 917 (AppKit) [0x7fff8aa72f7e]
12 _FSOperateOnObjectSync + 482 (CarbonCore) [0x7fff87ab309c]
12 _NodeOperation + 488 (DesktopServicesPriv) [0x7fff90d6e38a]
4 TFSCopyOperation::DoMoveToTrash(TCountedPtr<TCFURLInfo> const&) + 330 (DesktopServicesPriv) [0x7fff90d7e28c]
4 TFSInfo::MoveAndRenameTo(TCountedPtr<TFSInfo> const&, TUString*, TCountedPtr<TFSInfo>&) const + 677 (DesktopServicesPriv) [0x7fff90da4ae7]
4 TCFURLInfo::RenameWithoutReplacing(char const*, char const*, bool) + 162 (DesktopServicesPriv) [0x7fff90d89620]
4 __rename + 10 (libsystem_kernel.dylib) [0x7fff861ba97a]
3 <Suppressed>
3 TFSCopyOperation::DoMoveToTrash(TCountedPtr<TCFURLInfo> const&) + 1033 (DesktopServicesPriv) [0x7fff90d7e54b]
3 THFSPlusPropertyStore::SetProperty(TUString const&, unsigned int, TPropertyReference const&) + 81 (DesktopServicesPriv) [0x7fff90d26bc1]
3 TDSMutex::Acquire() + 34 (DesktopServicesPriv) [0x7fff90ce5d00]
3 __psynch_mutexwait + 10 (libsystem_kernel.dylib) [0x7fff861ba746]
1 <Suppressed>
2 TFSCopyOperation::DoMoveToTrash(TCountedPtr<TCFURLInfo> const&) + 995 (DesktopServicesPriv) [0x7fff90d7e525]
2 THFSPlusPropertyStore::SetProperty(TUString const&, unsigned int, TPropertyReference const&) + 81 (DesktopServicesPriv) [0x7fff90d26bc1]
2 TDSMutex::Acquire() + 34 (DesktopServicesPriv) [0x7fff90ce5d00]
2 __psynch_mutexwait + 10 (libsystem_kernel.dylib) [0x7fff861ba746]
1 <Suppressed>
所以代码应该在一个单独的线程上执行,事实上,这就是它在我的系统上的工作方式,但是不止一个客户在OS X 10.9.5上经历过这种情况。startClean中有几个对主线程的调用,但这些调用仅用于更新UI。trashMediaCache调用由performSelector:withObject:执行,但不由performSelectorOnMainThread执行
以前有人见过这个吗?这是一个OSX错误,还是存在系统设计将调用转移到主线程的情况?还是我只是误解了日志
另外,我知道我可以使用分派调用或操作队列,这可能会解决问题,但我仍然想知道原始问题的答案。显然,您在后台运行的
startClean
方法会触发一些代码在主线程上运行,从而导致死锁。一种可能性是
startClean
使用核心数据。这是描述的。另一种可能是在主线程上执行的完成处理程序。有很多,例如,
MKLocalSearchCompletionHandler
,其中文档明确声明它们总是在主线程上执行。\NSThread\uuuu main\uuu
不是主线程。它是NSThread执行的内部入口点。啊,我想你是对的。我刚从另一个应用程序收到一个挂起报告,调用堆栈从main
开始,而不是\uu\uu main\uuu
。我已经阅读了我自己的代码,我确信没有任何东西会进入主线程,所以它似乎最有可能发生在苹果的代码中。我可能永远也查不清事情的真相。
[NSThread detachNewThreadSelector:@selector(startClean) toTarget:self withObject:nil];