Replies: 1 comment
-
The CLR memory model documentation (#75790) may provide some help for you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I was recently reading Lazy.cs and noticed that the member
_state
isvolatile
. I think this is done to ensure proper acquire semantics and release semantics (as per the language specification) for theValue
property. More specifically, if_state
isnull
, it must mean that_value
is non-null
, because_state
is assigned last and none of the other writes like_value
can be reordered after it (there are also helpful comments to emphasize this point).However, does the
volatile
keyword also imply any behavior about the "freshness" of the other members access by a given thread? Is it possible that an old value of the non-volatile
member_value
is cached in some register by the time we read it? Perhaps this is processor-specific?I see that there are really three code paths for
Lazy<T>
values, so are there "freshness" guarantees made through the use of alock
forLazyThreadSafetyMode.ExecutionAndPublication
andInterlocked
forLazyThreadSafetyMode.PublicationOnly
that are not present forLazyThreadSafetyMode.None
?Beta Was this translation helpful? Give feedback.
All reactions