Thread hangs caused by mutex

When viewing the process: the process has been hung in the __pause_nocancel function, and then gdb debugging:

(gdb) bt

#0  0x000000385d60efe0 in __pause_nocancel () from /lib64/libpthread.so.0

#1  0x000000385d60917b in __pthread_mutex_lock_full () from /lib64/libpthread.so.0


(gdb) p  lock_test

$1 = {__data = {__lock = 4, __count = 0, __owner = 0, __nusers = 0, __kind = 0, __spins = 0, __list = {
      __prev = 0x0, __next = 0x1a36290}},   __size = "\004", '\000' <repeats 31 times>"\220, b\243\001\000\000\000", __align = 4}


And __owner = 0, indicating that no other threads occupy this lock, and __lock = 4 is very strange, 4 represents the thread id, and id is generally not so small, continue to view the source code:



This happens only when the error is found to be ESRCH and EDEADLK.



At present, only one thread uses this lock, so it is inferred that it is an ESRCH scenario, and __lock = 4, which infers that it may be caused by initializing this lock.

It is confirmed that the pthread_mutex_init() function is not called, and the solution is added.




Guess you like

Origin blog.csdn.net/zgb40302/article/details/52413899