Closed
Description
https://github.com/dotnet/runtime/blob/main/docs/design/specs/Memory-model.md describes how Object assignment to a location potentially accessible by other threads is a release with respect to accesses to the instance’s fields/elements and metadata. But this method only uses the local variable value
for locking. Any updates to value
will not be seen by other threads. It seems like this might be possible:
- Thread 1 sees
_importsCache == null
andvalue == null
and enters the first conditional - Thread 2 sees
_importsCache == null
andvalue == null
and enters the first conditional too - Thread 1 takes the lock, sees
value == null
and initializes_importsCache
to a new dictionary - Thread 2 takes the lock, see the local variable
value
is still null, and then re-initializes_importsCache
to another value.
Is this correct/possible?