Simplified question to give a clearer idea of ββwhat I am actually asking
I have two threads, name them Aand B. They divide one type object Foothat has a field under the name Nameand is stored in the type array Foo[]by index 0. Streams will always have access to the index 0in the order that is already guaranteed by the system, so there is no race condition for the stream Bpreceding the stream A.
This is the order.
array[0].Name = "Jason";
string theName = array[0].Name
As I said, this order is already guaranteed, there is no way for stream B to read the value before stream A
I want to provide two things:
- Both threads get the last object with index 0.
B .Name
Name, volatile , , volatile.
, 1, ( ), .VolatileRead:
Foo obj = (Foo)Thread.VolatileRead(ref array[0]);
obj.Name = "Jason";
Foo obj = (Foo)Thread.VolatileRead(ref array[0]);
string theName = obj.Name
:
array[0].Name = "Jason";
Thread.MemoryBarrier();
Thread.MemoryBarrier();
string theName = array[0].Name
, : , 2? , ? 0 , Name. VolatileRead MemoryBarrier 0 , IN 0 ?