2 using System.Threading;
4 public class InterlockTest
12 public static int Main() {
15 InterlockTest it = new InterlockTest ();
18 int c = Interlocked.Exchange (ref it.test, 1);
26 b = Interlocked.Increment (ref a);
33 b = Interlocked.Decrement (ref a);
39 string s = IncTest ();
47 Thread.MemoryBarrier ();
49 Console.WriteLine ("done!");
54 public static string IncTest () {
55 return "A" + Interlocked.Increment (ref s_test);