Versions Compared

Key

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

...

Based on runtime environment and the scheduler on the operating system, the following code will have different behaviors. Let's assume function thread1 and thread2 are called consecutively as in pthread_create is called from thread2 right after pthread_create in is called for thread1. If lucky, the code will run without any problems. In other times, the code will deadlock in which thread1 try to lock m1 while thread2 try to lock on m2 and the program will not progress.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

POS43-C

medium

probable

medium

P3

4

References

pthread_mutex tutorial

Other Languages

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