Cocoa 什么可能导致ImageProviderReleaseInfoCallback/\uuu自旋锁中出现死锁

Cocoa 什么可能导致ImageProviderReleaseInfoCallback/\uuu自旋锁中出现死锁,cocoa,deadlock,nsoperationqueue,cgimage,spinlock,Cocoa,Deadlock,Nsoperationqueue,Cgimage,Spinlock,我有一个Cocoa应用程序,它使用许多NSOperationQueue实例在后台处理图像。每个队列处理调用操作,这些调用操作基本上将NSImage对象转换为cgimagerf实例,使用: CGImageRef ref = [image CGImageForProposedRect:NULL context:nil hints:nil]; 一些用户抱怨该应用突然停止响应。我要求他们使用ActivityMonitor.app收集流程样本。这些报告都非常相似 在调用ImageProviderRele

我有一个Cocoa应用程序,它使用许多
NSOperationQueue
实例在后台处理图像。每个队列处理调用操作,这些调用操作基本上将
NSImage
对象转换为
cgimagerf
实例,使用:

CGImageRef ref = [image CGImageForProposedRect:NULL context:nil hints:nil];
一些用户抱怨该应用突然停止响应。我要求他们使用ActivityMonitor.app收集流程样本。这些报告都非常相似

在调用
ImageProviderReleaseInfoCallback
之后,当队列/线程卡在
\uuuuu spin\uu lock
时,主线程似乎正在通过自动释放池
排出

文档说明,
CGImageForProposedRect:
的所有参数都是可选的。如果可以从后台线程调用,他们不会说什么。也许这就是问题所在?我对此表示怀疑,因为它在几乎所有情况下都能正常工作(我发布了数百次应用程序,没有任何问题……)

你知道为什么排队会被卡住吗

全过程示例:

OS Version:      Mac OS X 10.6.8 (10K549)
Report Version:  6

Call graph:
    1971 Thread_905   DispatchQueue_1: com.apple.main-thread  (serial)
      1971 0x2e6d
        1971 NSApplicationMain
          1971 -[NSApplication run]
            1971 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
              1971 _DPSNextEvent
                1971 AEProcessAppleEvent
                  1971 aeProcessAppleEvent
                    1971 dispatchEventAndSendReply(AEDesc const*, AEDesc*)
                      1971 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned long, unsigned char*)
                        1971 _NSAppleEventManagerGenericHandler
                          1971 -[NSAutoreleasePool drain]
                            1971 NSPopAutoreleasePool
                              1971 _CFAutoreleasePoolPop
                                1971 CFRelease
                                  1971 -[NSImage dealloc]
                                    1971 -[NSImage _deallocAuxiliaryStorage]
                                      1971 -[NSCGImageSnapshotRep dealloc]
                                        1971 _CFRelease
                                          1971 image_finalize
                                            1971 _CFRelease
                                              1971 image_provider_finalize
                                                1971 ImageProviderReleaseInfoCallback
                                                  1971 __spin_lock
    1971 Thread_943   DispatchQueue_2: com.apple.libdispatch-manager  (serial)
      1971 start_wqthread
        1971 _pthread_wqthread
          1971 _dispatch_worker_thread2
            1971 _dispatch_queue_invoke
              1971 _dispatch_mgr_invoke
                1971 kevent
    1971 Thread_944   DispatchQueue_6: com.apple.root.default-priority  (concurrent)
      1971 start_wqthread
        1971 _pthread_wqthread
          1971 _dispatch_worker_thread2
            1971 _dispatch_call_block_and_release
              1971 ____NSOQSchedule_block_invoke_2
                1971 -[__NSOperationInternal start]
                  1971 -[NSInvocationOperation main]
                    1971 -[NSInvocation invoke]
                      1971 __invoking___
                        1971 0x17a64
                          1971 0x244cf
                            1971 0x22a97
                              1971 -[NSImage CGImageForProposedRect:context:hints:]
                                1971 -[NSImage _usingBestRepresentationForRect:context:hints:body:]
                                  1971 __-[NSImage CGImageForProposedRect:context:hints:]_block_invoke_1
                                    1971 -[NSImage _snapshotRepForRep:rect:context:processedHints:]
                                      1971 -[NSImage _createSnapshotRepForRep:rect:context:processedHints:]
                                        1971 -[NSImageRep CGImageForProposedRect:context:hints:flipped:]
                                          1971 -[NSIconRefImageRep CGImageForProposedRect:context:hints:]
                                            1971 _ISCreateCGImageForType
                                              1971 _ISGetCGImageRefForISImageRef
                                                1971 _ISImageRefIterator(void*, unsigned char, short (*)(void*, void*), void*)
                                                  1971 _ISGoThruImageStorages
                                                    1971 _ISGoThruImageStorages
                                                      1971 MergeBestStorageIntoContext(void*, void*)
                                                        1971 _CFRelease
                                                          1971 image_finalize
                                                            1971 _CFRelease
                                                              1971 image_provider_finalize
                                                                1971 ImageProviderReleaseInfoCallback
                                                                  1971 __spin_lock
    1971 Thread_980   DispatchQueue_6: com.apple.root.default-priority  (concurrent)
      1971 start_wqthread
        1971 _pthread_wqthread
          1971 _dispatch_worker_thread2
            1971 _dispatch_call_block_and_release
              1971 ____NSOQSchedule_block_invoke_2
                1971 -[__NSOperationInternal start]
                  1971 NSPopAutoreleasePool
                    1971 _CFAutoreleasePoolPop
                      1971 CFRelease
                        1971 -[NSImage dealloc]
                          1971 -[NSImage _deallocAuxiliaryStorage]
                            1971 -[NSCGImageSnapshotRep dealloc]
                              1971 _CFRelease
                                1971 image_finalize
                                  1971 _CFRelease
                                    1971 image_provider_finalize
                                      1971 ImageProviderReleaseInfoCallback
                                        1971 glueReleaseInfo
                                          1971 JP2ReleaseInfoCallback
                                            1971 _cg_JP2TearDownDecompressor
                                              1971 _CFRelease
                                                1971 __CFBasicHashDrain
                                                  1971 __CFDictionaryCallback
                                                    1971 _CFRelease
                                                      1971 _CGImageReadSessionFinalize
                                                        1971 _CFRelease
                                                          1971 _CGImageReadFinalize
                                                            1971 _CFRelease
                                                              1971 __CFDataDeallocate
                                                                1971 _ISReleaseStorageRef
                                                                  1971 _CFRelease
                                                                    1971 __CFArrayReleaseValues
                                                                      1971 _CFRelease
                                                                        1971 image_finalize
                                                                          1971 _CFRelease
                                                                            1971 image_provider_finalize
                                                                              1971 ImageProviderReleaseInfoCallback
                                                                                1971 __spin_lock
    1971 Thread_1013   DispatchQueue_6: com.apple.root.default-priority  (concurrent)
      1971 start_wqthread
        1971 _pthread_wqthread
          1971 _dispatch_worker_thread2
            1971 _dispatch_call_block_and_release
              1971 ____NSOQSchedule_block_invoke_2
                1971 -[__NSOperationInternal start]
                  1971 -[NSInvocationOperation main]
                    1971 -[NSInvocation invoke]
                      1971 __invoking___
                        1971 0x17a64
                          1971 0x244cf
                            1971 0x22a97
                              1971 -[NSImage CGImageForProposedRect:context:hints:]
                                1971 -[NSImage _usingBestRepresentationForRect:context:hints:body:]
                                  1971 __-[NSImage CGImageForProposedRect:context:hints:]_block_invoke_1
                                    1971 -[NSImage _snapshotRepForRep:rect:context:processedHints:]
                                      1971 -[NSImage _createSnapshotRepForRep:rect:context:processedHints:]
                                        1971 -[NSImageRep CGImageForProposedRect:context:hints:flipped:]
                                          1971 -[NSIconRefImageRep CGImageForProposedRect:context:hints:]
                                            1971 _ISCreateCGImageForType
                                              1971 _ISGetCGImageRefForISImageRef
                                                1971 _ISImageRefIterator(void*, unsigned char, short (*)(void*, void*), void*)
                                                  1971 _ISGoThruImageStorages
                                                    1971 MergeBestStorageIntoContext(void*, void*)
                                                      1971 _CFRelease
                                                        1971 image_finalize
                                                          1971 _CFRelease
                                                            1971 image_provider_finalize
                                                              1971 ImageProviderReleaseInfoCallback
                                                                1971 __spin_lock
    1971 Thread_1019   DispatchQueue_6: com.apple.root.default-priority  (concurrent)
      1971 start_wqthread
        1971 _pthread_wqthread
          1971 _dispatch_worker_thread2
            1971 _dispatch_call_block_and_release
              1971 ____NSOQSchedule_block_invoke_2
                1971 -[__NSOperationInternal start]
                  1971 NSPopAutoreleasePool
                    1971 _CFAutoreleasePoolPop
                      1971 CFRelease
                        1971 -[NSImage dealloc]
                          1971 -[NSImage _deallocAuxiliaryStorage]
                            1971 -[NSCGImageSnapshotRep dealloc]
                              1971 _CFRelease
                                1971 image_finalize
                                  1971 _CFRelease
                                    1971 image_provider_finalize
                                      1971 ImageProviderReleaseInfoCallback
                                        1971 __spin_lock
    1971 Thread_1031
      1971 thread_start
        1971 _pthread_start
          1971 startIOThread(void*)
            1971 CVDisplayLink::runIOThread()
              1971 pthread_cond_wait$UNIX2003
                1971 _pthread_cond_wait
                  1971 __semwait_signal

Total number in stack (recursive counted multiple, when >=5):
        17       _CFRelease
        6       ImageProviderReleaseInfoCallback
        6       image_finalize
        6       image_provider_finalize
        5       __spin_lock
        5       _dispatch_worker_thread2
        5       _pthread_wqthread
        5       start_wqthread

Sort by top of stack, same collapsed (when >= 5):
        __spin_lock        9855
        __semwait_signal        1971
        kevent        1971