根據Web,我找到了下面的代碼,相當於VB.NET的C#Volatile。當我正好運行MemoryBarrier()時發生了什麼?怎麼樣?
碼參考:How do I specify the equivalent of volatile in VB.net?
Function VolatileRead(Of T)(ByRef Address As T) As T
VolatileRead = Address
Threading.Thread.MemoryBarrier() '*** I mean this line ***'
End Function
Sub VolatileWrite(Of T)(ByRef Address As T, ByVal Value As T)
Threading.Thread.MemoryBarrier() '*** I mean this line ***'
Address = Value
End Sub
我想確切地知道,什麼是Threading.Thread.MemoryBarrier()做的怎麼樣,當我在上面的代碼中執行它?
我可以在C#中自己編寫一個等價於MemoryBarrier()的方法嗎?
[良好的開端(HTTP ://www.albahari.com/threading/part4.aspx#_Memory_Barriers_and_Volatility)。 – Sinatr
@Sinatr非常感謝 – Behzad