Z
Zuma
Assuming I have a class like the following;
public class Family
{
private *volatile* Person _child;
public Person Child
{
get { return _child; }
set { _child = value; }
}
}
An instance of this class is shared by multiple threads in a multiprocessor
system and the Child property can be read or written by any of them. In such
a case, should I define the _child variable as volatile because of cache
coherency? I'm asking it because the source code (.NET Reflector) of "thread
safe" classes in the .NET Framework do not specify the volatile keyword when
defining publicly readable/writable member variables. Most of the documents
I've found on the Internet talk about the synchronization, memory barriers
and instruction reordering issues when explaining the volatile keyword, but
none of them mentions the cache coherency in detail.
public class Family
{
private *volatile* Person _child;
public Person Child
{
get { return _child; }
set { _child = value; }
}
}
An instance of this class is shared by multiple threads in a multiprocessor
system and the Child property can be read or written by any of them. In such
a case, should I define the _child variable as volatile because of cache
coherency? I'm asking it because the source code (.NET Reflector) of "thread
safe" classes in the .NET Framework do not specify the volatile keyword when
defining publicly readable/writable member variables. Most of the documents
I've found on the Internet talk about the synchronization, memory barriers
and instruction reordering issues when explaining the volatile keyword, but
none of them mentions the cache coherency in detail.