
...
Deadlock requires all four conditions, so , to prevent deadlock, prevent any one of the four conditions. This guideline recommends locking the mutexes in a predefined order to prevent circular wait. This rule is a specific instance of CON35-C. Avoid deadlock by locking in predefined order using POSIX threads.
...
The solution to the deadlock problem is to use a predefined order for the locks in the deposit()
function. In the following compliant solution, each thread will lock based on an the id basis of the bank_account
ID, defined defined in the struct initialization. This solution prevents the circular wait problem.
...
Deadlock prevents multiple threads from progressing, thus halting the executing program. This is a potential A denial-of-service attack is possible because the attacker can force deadlock situations. Deadlock is likely to occur in multithreaded programs that manage multiple shared resources.
...
The CERT Oracle Secure Coding Standard for Java: LCK07-J. Avoid deadlock by requesting and releasing locks in the same order
MITRE CWE: CWE-764] Multiple Locks locks of Critical Resourcescritical resources
...
Sources
[Barney 2010] pthread_mutex tutorial
[Bryant 2003] Chapter 13, "Concurrent Programming"
...