1

在我的 iPhone 应用程序中,我发布了一个 AVAudioPlayer 实例(这样我就可以用不同的 URL 初始化另一个实例)。通常这工作正常,但偶尔我会在主线程上遇到死锁:

Thread 1, Queue : com.apple.main-thread
#0  0x357e00d8 in __psynch_mutexwait ()
#1  0x3497d67a in pthread_mutex_lock ()
#2  0x359997a6 in -[AVAudioPlayer privCommonCleanup] ()
#3  0x35999bb6 in -[AVAudioPlayer dealloc] ()
#4  0x3338a174 in _objc_rootRelease ()

该应用程序只是停止,不接受任何输入。没有崩溃或任何事情,它只是停止。

它似乎没有与应用程序中的任何其他线程进行交互,但为了完整起见,它们是:

Thread 2, Queue : com.apple.libdispatch-manager
#0  0x357d03a8 in kevent ()
#1  0x33b03eaa in _dispatch_mgr_invoke ()
#2  0x33b03bc8 in _dispatch_mgr_thread ()
Thread 3, Queue : (null)
#0  0x357e0cd4 in __workq_kernreturn ()
#1  0x34983f3c in _pthread_wqthread ()
#2  0x34983cd0 in start_wqthread ()
Thread 4 WebThread, Queue : (null)
#0  0x357d0004 in mach_msg_trap ()
#1  0x357d0200 in mach_msg ()
#2  0x3573e3f2 in __CFRunLoopServiceMachPort ()
#3  0x3573d12a in __CFRunLoopRun ()
#4  0x356c04a4 in CFRunLoopRunSpecific ()
#5  0x356c036c in CFRunLoopRunInMode ()
#6  0x37406ca2 in _ZL12RunWebThreadPv ()
#7  0x34989734 in _pthread_start ()
#8  0x349895f0 in thread_start ()
Thread 5, Queue : (null)
#0  0x357e0cd4 in __workq_kernreturn ()
#1  0x34983f3c in _pthread_wqthread ()
#2  0x34983cd0 in start_wqthread ()
Thread 6 AQClient, Queue : (null)
#0  0x357d0004 in mach_msg_trap ()
#1  0x357d0200 in mach_msg ()
#2  0x3573e3f2 in __CFRunLoopServiceMachPort ()
#3  0x3573d12a in __CFRunLoopRun ()
#4  0x356c04a4 in CFRunLoopRunSpecific ()
#5  0x356c036c in CFRunLoopRunInMode ()
#6  0x34e2cb2e in GenericRunLoopThread::Entry(void*) ()
#7  0x34db3ca2 in CAPThread::Entry(CAPThread*) ()
#8  0x34989734 in _pthread_start ()
#9  0x349895f0 in thread_start ()
Thread 7, Queue : (null)
#0  0x357d0004 in mach_msg_trap ()
#1  0x357d0200 in mach_msg ()
#2  0x3573e3f2 in __CFRunLoopServiceMachPort ()
#3  0x3573d12a in __CFRunLoopRun ()
#4  0x356c04a4 in CFRunLoopRunSpecific ()
#5  0x356c036c in CFRunLoopRunInMode ()
#6  0x34af9b74 in -[NSRunLoop(NSRunLoop) runMode:beforeDate:] ()
#7  0x34b13522 in -[NSRunLoop(NSRunLoop) run] ()
#8  0x000c83fe in +[AFURLConnectionOperation networkRequestThreadEntryPoint:] at /Users/hiltonc/Documents/Code/LDSMobileApps/LDSScriptureHeroes/External/LDSMobileAccount/External/AFNetworking/AFNetworking/AFURLConnectionOperation.m:151
#9  0x34b05a80 in -[NSThread main] ()
Thread 8 com.apple.NSURLConnectionLoader, Queue : (null)
#0  0x357d0004 in mach_msg_trap ()
#1  0x357d0200 in mach_msg ()
#2  0x3573e3f2 in __CFRunLoopServiceMachPort ()
#3  0x3573d12a in __CFRunLoopRun ()
#4  0x356c04a4 in CFRunLoopRunSpecific ()
#5  0x356c036c in CFRunLoopRunInMode ()
#6  0x34b05bb8 in +[NSURLConnection(Loader) _resourceLoadLoop:] ()
#7  0x34b05a80 in -[NSThread main] ()
Thread 12 com.apple.CFSocket.private, Queue : (null)
#0  0x357e0570 in select$DARWIN_EXTSN ()
#1  0x35742640 in __CFSocketManager ()
#2  0x34989734 in _pthread_start ()
#3  0x349895f0 in thread_start ()

我真的不知道如何深入了解这个问题。有任何想法吗?

4

1 回答 1

3

释放一个并在委托调用中替换它肯定会导致这种类型的问题。基本上你想运行(在 ARC 下):

avPlayer.delegate = nil
[avPlayer stop];
avPlayer = nil; //overkill
avPlayer = [AVPlayer alloc] init....
avPlayer ....

如果您发现需要在委托方法中执行上述操作,则只需将上述代码包装在一个块中并将其分派到主队列(我假设 avPlayer 是一个 ivar 或属性)。

于 2012-07-17T13:14:00.753 回答