Can I force an order lock to prevent deadlocks?

I inherited a large project with a long history, and my task is to establish a bunch of dead ends that have been recorded over the years.

I understand the nature of several dead ends and can reproduce them sequentially using some carefully placed Sleepsand other forced timings.

But fixing dead ends is not so simple. The code was not written with any strategy for locking resources. I can use solutions for each deadlock, but much of this comes down to the problem of locking ordering.

For example, Worker 1:

Acquires resource A
{
  ...
  Acquires resource B
  {
    ...
  }
}

While worker 2 does this:

Acquires resource B
{
  ...
  Acquires resource A
  {
    ...
  }
}

, : / ? ? , ()? ?

.

+4
1

, . , A, B, B, A. , . , , . , , ( , ).

. , A = 100, B = 130. : X, , Y > X. B A .

, . , , , , , .

+2

Source: https://habr.com/ru/post/1540254/


All Articles