pthread_mutex_unlock()出错

简介: pthread_mutex_unlock()出错

出外转了一圈,回来看到崩溃:


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;
}

 

目录
相关文章
|
4月前
|
Python
Mutex
【7月更文挑战第2天】
24 2
|
6月前
|
存储 缓存 安全
C语言进程(第二章,wait,sleep,waitpid,pthread_mutex_lock,pthread_mutex_unlock)
C语言进程(第二章,wait,sleep,waitpid,pthread_mutex_lock,pthread_mutex_unlock)
127 0
C++11/14/17中提供的mutex系列区别
C++11/14/17中提供的mutex系列类型如下:
|
调度 C++
C++11之线程库(Thread、Mutex、atomic、lock_guard、同步)
C++11之线程库(Thread、Mutex、atomic、lock_guard、同步)
209 0
使用超时加锁:pthread_mutex_timedlock
使用超时加锁:pthread_mutex_timedlock
268 0
|
Linux API
pthread_mutex_init & 互斥锁pthread_mutex_t的使用
pthread_mutex_init l         头文件: #include l         函数原型: int pthread_mutex_init(pthread_mutex_t *restrict mutex,const pthread_mutexattr_t *restrict attr); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; l         函数作用: 该函数用于C函数的多线程编程中,互斥锁的初始化。
1934 0
|
C++
【C++ 语言】pthread_mutex_t 互斥锁
【C++ 语言】pthread_mutex_t 互斥锁
289 0
pthread_mutex_unlock()出错
pthread_mutex_unlock()出错
336 0