Versions Compared

Key

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

...

Deadlock can happen when multiple threads each holds a lock the other needs and are waiting for each other to release the resource. One way to fix the problem is to avoid circular wait by locking the mutex in a predefined order.

CON12-J. Avoid deadlock by requesting and releasing locks in the same+order describes the deadlock solution for Java

Noncompliant Code Example

...

The solution to the deadlock problem is to lock in predefined order. In the following example, each thread will lock m1 first then m2. This way circular wait problem is avoided and when one thread requires a lock will guarantee it will require the next lock.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

POS43-C

medium

probable

medium

P2 P3

6 4

References

Other Languages

...