2 using System
.Threading
;
4 public class InterlockTest
9 public static int Main() {
13 InterlockTest it
= new InterlockTest ();
17 int c
= Interlocked
.Add (ref it
.test
, 1);
25 b
= Interlocked
.Add (ref a
, 1);
33 long lc
= Interlocked
.Add (ref it
.ltest
, 1);
41 lb
= Interlocked
.Add (ref la
, 1);
47 if (Interlocked
.Read (ref la
) != 2)
51 lc
= Interlocked
.Exchange (ref la
, 2);
59 InterlockTest o1
= new InterlockTest ();
60 InterlockTest o2
= new InterlockTest ();
63 InterlockTest o3
= Interlocked
.CompareExchange (ref o
, o2
, o2
);
69 InterlockTest o4
= Interlocked
.CompareExchange (ref o
, o2
, o1
);
75 Console
.WriteLine ("done!");