ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Inconsistent order of taken locks

Last modified: 11 February 2024

If your class has multiple resources protected with locks to achieve thread safety, ReSharper analyzes possible execution paths in multi-threaded environment (assuming public API of the class can be used simultaneously by multiple threads) and the order of locks taken on such execution paths to find cycles leading to possible deadlocks at runtime, as illustrated in the example below. The warning message provides a detailed explanation and an example of a cycle that could be formed.