Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Mutexes are often used for critical resources to prevent multiple threads from accessing them at the same time. Sometimes, when locking mutexes, deadlock will happen when multiple threads hold each other's lock, and the program consequently comes to a halt. There are four requirements for deadlock:

...

The following code has behavior which is dependend dependent on the runtime environment and the platform's scheduler. However, with proper timing, the main() function will deadlock when running thr1 and thr2 in which , where thr1 tries to lock ba2's mutex, while thr2 tries to lock on ba1's mutex in the deposit() function, and the program will not progress.

...

Deadlock causes multiple threads to become unable to progress and , thus halts halting the executing program. This is a potential denial-of-service attack because the attacker can force deadlock situations. It is likely for deadlock to occur in multi-threaded multithreaded programs that manage multiple shared resources.

Recommendation

Severity

Likelihood

Remediation Cost

Level

Priority

CON35-C

low

probable

medium

L3

P3

Other Languages

Related Guidelines

The CERT Oracle This rule appears in the Java Secure Coding Standard as for Java: LCK07-J. Avoid deadlock by requesting and releasing locks in the same order.

MITRE CWE: CWE-764] Multiple Locks of Critical Resources

Bibliography

Wiki Markup
\[[pthread_mutex | https://computing.llnl.gov/tutorials/pthreads/#Mutexes]\]  pthread_mutex tutorial
\[[MITRE CWE:764 | http://cwe.mitre.org/data/definitions/764.html]\] Multiple Locks of Critical Resources
\[[Bryant 032003|AA. Bibliography#Bryant 03]\] Chapter 13, Concurrent Programming

...