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: Possible incorrect implementation of Double-Check Locking pattern. Possible multiple write access to checked field.

Last modified: 11 February 2024

Consider the following piece of code:

Given the above code, writes that initialize the Foo instance could be delayed until the write of the instance value, thus creating the possibility that the instance returns an object in an uninitialized state.

In order to avoid this, the instance value must be made volatile.