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 c = Interlocked.CompareExchange (ref it.test, 1, -2);
34 b = Interlocked.Increment (ref a);
41 b = Interlocked.Decrement (ref a);
47 string s = IncTest ();
55 Thread.MemoryBarrier ();
57 Console.WriteLine ("done!");
62 public static string IncTest () {
63 return "A" + Interlocked.Increment (ref s_test);