VB.Net does not have an equivalent of C# volatile keyword so you have to manually implement volatile which is usually done by calling Thread.MemoryBarrier() before read and after write. So something like this is equivalent to declaring C# volatile variable:
''' <summary>
''' Gets a value indicating whether this instance is disposed.
''' </summary>
Public Property IsDisposed As Boolean
Get
Threading.Thread.MemoryBarrier()
Return _isDisposed
End Get
Private Set(value As Boolean)
_isDisposed = value
Threading.Thread.MemoryBarrier()
End Set
End Property
I am wondering of the memory barrier before read is necessary if the only place where I write to the variable is through a setter and there I always call Thread.MemoryBarrier() after the write.
Can I safely remove the Thread.MemoryBarrier() before read?
Edit: To make it more clear I am asking if I can remove the Thread.MemoryBarrier() before read in order to remove costs of memory fence for each read.