updating to the latest module.
[mono.git] / mono / tests / interlocked.cs
1 using System;
2 using System.Threading;
3
4 public class InterlockTest
5 {
6         public int test;
7         public int add;
8         public int rem;
9
10         static int s_test;
11         
12         public static int Main() {
13                 int a,b;
14
15                 InterlockTest it = new InterlockTest ();
16
17                 it.test = 0;
18                 int c = Interlocked.Exchange (ref it.test, 1);
19                 if (c != 0)
20                         return -1;
21
22                 if (it.test != 1)
23                         return -2;
24
25                 a = 1;
26                 b = Interlocked.Increment (ref a);
27                 if (a != 2)
28                         return -3;
29                 if (b != 2)
30                         return -4;
31
32                 a = 2;
33                 b = Interlocked.Decrement (ref a);
34                 if (b != 1)
35                         return -3;
36                 if (a != 1)
37                         return -4;
38
39                 string s = IncTest ();
40                 if (s != "A1")
41                         return -5;
42
43                 s = IncTest ();
44                 if (s != "A2")
45                         return -6;
46
47                 Console.WriteLine ("done!");
48
49                 return 0;
50         }
51
52         public static string IncTest () {
53                 return "A" + Interlocked.Increment (ref s_test);
54         }
55 }