Is memory protection (.net x86 or x64) required when dereferencing fields?

In the code, as shown below, if Proc1 and Proc2 run simultaneously on different processors, is it possible for ThingVal2 to get a value other than 5 (for example, zero)?

Class SimpleThing
    Public X As Integer
    Sub New (ByVal value As Integer)
        X = value
    End sub
End class
Class ConcurrencyTest
    Dim Thing1 As New SimpleThing (5)
    Dim Thing2 As New SimpleThing (0)
    Dim ThingRef As SimpleThing = Thing1
    Dim ThingVal1, ThingVal2 As Integer
    Sub Proc1 ()
        Thing2.X = 5
        Threading.Thread.MemoryBarrier ()
        ThingRef = Thing2
    End sub
    Sub Proc2 ()
        ThingVal1 = Thing2.X
        ThingVal2 = ThingRef.X
    End sub
End class

, , IA64, , Proc2 , ThingRef , X Thing2 . .Net, x86 x64? Proc1 SimpleThing, X 5, ThingRef, , , , , , - , Proc2?

(, Interlocked.CompareExchange). x86/x64 ? , vb.net ?

, , , (, - IA64, )?

+3
1

, . , .

-1. :

CLR, 2.0 . , ThingVal 5 x86/x64. . IA64, IA64, CLR .

-2. ad IA64 vs x86/x64:

x86/x64 , IA64 . , , (, ++), , , . : VB .., .

-3. ad immutable:

, , .

-4. ad single core:

. , . ( .net .) .

, # volatile. , - , , , . , VB .

0

Source: https://habr.com/ru/post/1785560/


All Articles