If you have a construct like this, it seems possible according to the linked article (https://msdn.microsoft.com/en-us/magazine/jj883956.aspx paragraph Read Introduction) ...
var temp = myRef;
temp.DoSomething1();
//... at a later time
temp.DoSomething2();
... that temp variable is optimized away by the jitter by a read introduction.
Question is: Is there a way to guarantee that I really work with the copy of the reference and not with an intrduced read of the origianl reference. Since in my program myRef can change all the time by assigning a new object, I need to make sure, that I access the same object during the whole function whenever I need to do something with the object.
What about:
- temp = Thread.VolatileRead(myRef)
- temp = Volatile.Read(myRef)
- temp = CompareExchange (myRef, null, null);
Can it still happen, that the jitter does call one of the read operations several times instead creating a copy of the reference?