出外转了一圈,回来看到崩溃:
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `./gh_manager thread false 1'. Program terminated with signal SIGSEGV, Segmentation fault. #0 __pthread_mutex_unlock_usercnt (decr=1, mutex=0x0) at pthread_mutex_unlock.c:313 313 pthread_mutex_unlock.c: 没有那个文件或目录. [Current thread is 1 (Thread 0x7f3a67113700 (LWP 31273))] (gdb) backtrace #0 __pthread_mutex_unlock_usercnt (decr=1, mutex=0x0) at pthread_mutex_unlock.c:313 #1 __GI___pthread_mutex_unlock (mutex=0x0) at pthread_mutex_unlock.c:314
意思就是说,pthread_mutex_unlock出错了,传递的参数为NULL。嗯?这怎么可能?到处是成对出现。唯一的可能性:
(函数1)unlock,(函数2)lock,(函数1)delete,(函数2)unlock。
故修改函数1如下:
void H264Writer::end() { if (h264_mutex == NULL) { return; } pthread_mutex_lock(h264_mutex); ...... //避免别的地方见缝插针。 pthread_mutex_t* temp_mutex = h264_mutex; h264_mutex = NULL; pthread_mutex_unlock(temp_mutex); delete temp_mutex; }