I have a multi-threads program which is running on Linux, sometimes if I run gstack against it, there is a thread was waiting for a lock for a long time(say, 2-3 minutes),
Thread 2 (Thread 0x5e502b90 (LWP 19853)):
0 0x40000410 in __kernel_vsyscall ()
1 0x400157b9 in __lll_lock_wait () from /lib/i686/nosegneg/libpthread.so.0
2 0x40010e1d in _L_lock_981 () from /lib/i686/nosegneg/libpthread.so.0
3 0x40010d3b in pthread_mutex_lock () from /lib/i686/nosegneg/libpthread.so.0
...
I checked the rest of the threads, none of them were taking this lock, however, after a while this thread (LWP 19853) could acquire this lock successfully.
There should exist one thread that had already acquired this lock, but I failed to find it, is there anything I missing?
EDIT: The definition of the pthread_mutex_t:
typedef union
{
struct __pthread_mutex_s {
int __lock;
unsigned int __count;
int __owner;
/* KIND must stay at this position in the structure to maintain binary compatibility. */
int __kind;
unsigned int __nusers;
extension union { int __spins; __pthread_slist_t __list; };
} __data;
char _size[_SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
There is a member "__owner", it is the id of the thread who is holding the mutex now.