Child pages
  • Multithreading


Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed typo

...

If two lock cascades are requested from two different threads at the same time and both threads request the same locks but in a different order, a dead lock can occur. In the simplest dead lock situation, one thread T1 already holds lock L1 and is going to request lock L2 while another thread T2 already holds lock L2 and is going to request lock L2L1.

There are several solutions available you can read in the internet to avoid that problem. One of them suggests to mark all locks with unique numbers and to write all code to request its desired locks in order from the lowest lock number ascending. In the example from above, thread T2 would violate against that guideline and thus the code would need to be rewritten so that it first requests L1 and then L2, which prevents the deadlock situation.

...