简体   繁体   English

Pthread互斥锁锁定声明失败

[英]Pthread mutex lock assertion fails

It's several days I'm trying to get ahead of this issue but seems like not my fault. 我试图解决这个问题已经过了几天,但似乎不是我的错。 I can't post any code because it's big enough. 我无法发布任何代码,因为它足够大。 I'll try to explain it as better as I can. 我会尽力更好地解释它。 First it is a multithreaded server application which receive request from multiple clients, also at same time, and elaborate it using master-workers (pool of threads) style with AF_UNIX sockets. 首先,它是一个multithreaded server application ,它同时接收来自多个客户端的请求,并使用具有AF_UNIX套接字的主工作程序(线程池)样式来详细说明该请求。 While it's running it often return this error : 在运行时,通常会返回以下错误:

[name]: ../nptl/pthread_mutex_lock.c:81: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed. [名称]:../nptl/pthread_mutex_lock.c:81:__pthread_mutex_lock:断言`mutex-> __ data .__ owner == 0'失败。

I'm not able to replicate this error or to catch it with valgrind or gdb (I tried several times). 我无法复制此错误,也无法使用valgrind或gdb捕获它(我尝试了几次)。 I use several global pthread_mutex_t initialized with PTHREAD_MUTEX_INITIALIZER and I never destroy them. 我使用了几个用PTHREAD_MUTEX_INITIALIZER初始化的全局pthread_mutex_t ,而且我从不销毁它们。 I'm pretty sure to lock and unlock them safely around the code like this: 我很确定可以围绕这样的代码安全地锁定和解锁它们:

  1. pthread_mutex_lock(&mutex);
  2. if something fails and I've to return from a thread: pthread_mutex_unlock(&mutex); 如果失败,则必须从线程返回: pthread_mutex_unlock(&mutex); and return (void*) -1; return (void*) -1;
  3. else : do things with shared variables else:用共享变量做事
  4. pthread_mutex_unlock(&mutex);

I've read that it could be caused by a lower level race condition in pthread_mutex_lock file but I'm not sure. 我已经读到它可能是由于pthread_mutex_lock文件中的较低级别竞争条件引起的,但我不确定。 By the way I would understand why this assertion could fails generically 顺便说一句我就明白为什么这个断言可能失败一般

This usually indicates that the lock has become corrupted in some way. 这通常表明锁已以某种方式损坏。 One possibility is that you are trying to lock a lock that was never initialized or has already been destroyed and not re-initialized. 一种可能性是您试图锁定从未初始化的锁,或者已经被销毁且尚未重新初始化的锁。 Another possibility is that some other piece of code is stomping on the mutex, possibly by accessing an array out of bounds or by accessing some memory after it has been freed. 另一种可能性是,互斥量上踩着其他一些代码,可能是通过超出范围访问数组或在释放数组后访问某些内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM