Let's say I have some variable x
(of type myClass
), which is initially null
and some assignment
x = myObject
occuring exactly once in some background thread.
Is it guaranteed that x
always contains either null
or myObject
when accessed from the main thread? Or is it possible that x
contains some invalid data shortly?
Provided the size of the type reference is the same size as the native word size of the CPU, then the assignment will be atomic (and safe in your described scenario).
In fact, (don't have the reference to hand) I'm fairly certain that a type ref will always be the same size as the native CPU word size.
From this (although it deals with somewhat different topic) I conclude that assignments are atomc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With