lundi 12 mai 2014

Can lock ordering be enforced / detected to prevent deadlocks?


Vote count:

1




I have inherited a big project with long history, and my task is to fix a bunch of deadlocks that have been reported over the years.


I understand the nature of a few deadlocks, and can reproduce them consistently using some carefully-placed Sleeps and other forced-timings.


But, fixing the deadlocks is not so simple. The code was not written with any strategy with regards to locking resources. I can hand-craft solutions for every deadlock, but much of it boils down to a problem of lock ordering.


For example, Worker 1:



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


While worker 2 does this:



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


So my question is: What is the best way to detect and/or enforce lock ordering problems in the code? Static analysis? Is there a compile-time way to detect this (ideal)? Or must I resort to detecting this kind of problem at runtime?


Any help is appreciated.



asked 1 min ago

tenfour

16.1k





Aucun commentaire:

Enregistrer un commentaire