This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: how to find the mutex lock holder in pthread program?
- From: Ryan Arnold <ryan dot arnold at gmail dot com>
- To: Han <keepsimple at gmail dot com>
- Cc: libc-help at sourceware dot org
- Date: Mon, 22 Feb 2010 00:42:54 -0600
- Subject: Re: how to find the mutex lock holder in pthread program?
- References: <37666aa81002212226r5eaf09b8uef4b854e81aa63f3@mail.gmail.com>
On Mon, Feb 22, 2010 at 12:26 AM, Han <keepsimple@gmail.com> wrote:
> Hi,
> I am using pthread in a C program. I found my program randomly hung
> because one thread failed to obtain the mutex lock. The error code is
> EBUSY. I am wondering how can I find out what is the thread holding
> the mutex lock at that point?
>
> thanks.
> Han
>
Hi Han,
Use GDB (Gnu Debugger) and attach it to the hung program. Then use
"thread apply all bt" (I think but I don't have a system handy).
It'll give you a backtrace of all of the threads and you should be
able to see which thread is doing what.
If this problem is easily reproducible too you can use strace to give
you some info one which locks are being taken.
Ryan