how to find the mutex lock holder in pthread program?

Ryan Arnold
Mon Feb 22 06:43:00 GMT 2010

On Mon, Feb 22, 2010 at 12:26 AM, Han <> 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.


More information about the Libc-help mailing list