On unix, a process is stuck, you doubt that it may be deadlock, find the reasons for deadlocking and how to remove and avoid it ?
I know the 4 conditions for deadlock:
-
Mutual exclusion: A resource can be assigned to at most one process at a time (no sharing).
-
Hold and wait: A processing holding a resource is permitted to request another.
-
No preemption: A process must release its resources; they cannot be taken away.
-
Circular wait: There must be a chain of processes such that each member of the chain is waiting for a resource held by the next member of the chain.
But, they are theoretical, how to determine a deadlock on unix practically ?
Only by seeing that a process does not make progress ?
How to find which part of the code cause the deadlock and the reasons ?
If you are allowed to use tools, what can be used ?
thanks
There is also Valgrind’s Helgrind tool: Helgrind: a thread error detector
Problems like these often result in unreproducible, timing-dependent crashes, deadlocks and other misbehaviour, and can be difficult to find by other means.
Helgrind is aware of all the pthread abstractions and tracks their effects as accurately as it can. On x86 and amd64 platforms, it understands and partially handles implicit locking arising from the use of the LOCK instruction prefix.
Helgrind works best when your application uses only the POSIX pthreads API. However, if you want to use custom threading primitives, you can describe their behaviour to Helgrind using the ANNOTATE_* macros defined in helgrind.h. This functionality was added in release 3.5.0 of Valgrind, and is considered experimental.