pthread_cond_signal deadlocks
What could be the cause if a call to pthread_cond_signal
deadlocks?
From what I understand (man page), it is implemented internally with a mutex, but what could cause this internal mutex lock operation to deadlo开发者_JAVA技巧ck?
EDIT: I am debugging an application which seem to deadlock on some occasions. A few of the stacktraces look like this:
Thread 1 (Thread 0xf6dff6c0 (LWP 32001)):
#0 0xffffe410 in __kernel_vsyscall ()
#1 0x00af15de in __lll_mutex_lock_wait () from /lib/tls/libpthread.so.0
#2 0x00aef3eb in pthread_cond_signal@@GLIBC_2.3.2 () from /lib/tls/libpthread.so.0
#3 0xf4cc8d83 in xxx
Well, one thing to look for might be this caveat from the man page, which sounds particularly applicable:
The condition functions are not async-signal safe, and should not be called from a signal handler. In particular, calling
pthread_cond_signal
orpthread_cond_broadcast
from a signal handler may deadlock the calling thread.
Apart from that, you could also see this if the internal mutex within the pthread_cond_t
has been overwritten by a stray write beyond the bounds of some other variable.
精彩评论