Reads and writes to certain primitive types in C# such as bool
and int
are atomic.
(See section 5.5, \"5.5 Atomicity of variable reference
I'm a little unclear as to what you are asking here. It seems like you could be asking 1 of 2 questions
_foo
while calling MyProperty atomic?For #1 the answer is yes. As the C# language spec (and CLI) states, the read and write of variables of certain specified types are guaranteed to be atomic. The type 'bool' is one of those types.
As for #2 the best place to look is section 12.6.6 of the CLI spec. It states that
A conforming CLI shall guarantee that read and write access to properly aligned memory locations no larger than the native word size (the size of type native int) is atomic
Considering to use the return value of MyProperty you must either be reading or writing the value, it's safe to assume it is set atomically.