Open IvanChan opened 7 years ago
It looks like Audio_Stream::~Audio_Stream()
& decodeSinglePacket
is called at the same time in different thread.
Code below might crash when Audio_Stream::~Audio_Stream()
come, m_packetQueueMutex won't work in Audio_Stream::~Audio_Stream()
void Audio_Stream::decodeSinglePacket(CFRunLoopTimerRef timer, void *info)
{
......
pthread_mutex_lock(&THIS->m_packetQueueMutex);
if (THIS->m_numPacketsToRewind > 0) {
AS_TRACE("Rewinding %i packets\n", THIS->m_numPacketsToRewind);
queued_packet_t *front = THIS->m_playPacket;
while (front && THIS->m_numPacketsToRewind-- > 0) {
queued_packet_t *tmp = front->next;
front = tmp;
}
THIS->m_playPacket = front;
THIS->m_numPacketsToRewind = 0;
}
pthread_mutex_unlock(&THIS->m_packetQueueMutex);
.......
Thread 23 Crashed:
0 MyApp 0x000000010012d704 astreamer::Audio_Stream::decodeSinglePacket(__CFRunLoopTimer*, void*) (audio_stream.cpp:1617)
1 CoreFoundation 0x0000000181321794 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 28 2 CoreFoundation 0x0000000181321438 CFRunLoopDoTimer + 884 3 CoreFoundation 0x000000018131eb4c CFRunLoopRun + 1520 4 CoreFoundation 0x0000000181248c50 CFRunLoopRunSpecific + 384 5 CoreFoundation 0x00000001812963a4 CFRunLoopRun + 1126 MyApp 0x000000010012ad04 astreamer::Audio_Stream::decodeLoop(void*) (audio_stream.cpp:1737)
7 libsystem_pthread.dylib 0x0000000180fcfb28 _pthread_body + 156 8 libsystem_pthread.dylib 0x0000000180fcfa8c _pthread_body + 0 9 libsystem_pthread.dylib 0x0000000180fcd028 thread_start + 4Thread 29: 0 libsystem_kernel.dylib 0x0000000180ee8fd8 mach_msg_trap + 8 1 CoreFoundation 0x0000000181320c60 CFRunLoopServiceMachPort + 196 2 CoreFoundation 0x000000018131e964 CFRunLoopRun + 1032 3 CoreFoundation 0x0000000181248c50 CFRunLoopRunSpecific + 384 4 CoreFoundation 0x00000001812963a4 CFRunLoopRun + 112
5 MyApp 0x000000010012ad04 astreamer::Audio_Stream::decodeLoop(void*) (audio_stream.cpp:1737)
6 libsystem_pthread.dylib 0x0000000180fcfb28 _pthread_body + 156 7 libsystem_pthread.dylib 0x0000000180fcfa8c _pthread_body + 0 8 libsystem_pthread.dylib 0x0000000180fcd028 thread_start + 4