New test.
[mono.git] / mono / tests / interlocked-2.2.cs
1 using System;
2 using System.Threading;
3
4 public class InterlockTest
5 {
6         public int test;
7         public int ltest;
8
9         public static int Main() {
10                 int a,b;
11                 long la, lb;
12
13                 InterlockTest it = new InterlockTest ();
14
15                 /* int */
16                 it.test = 2;
17                 int c = Interlocked.Add (ref it.test, 1);
18                 if (c != 3)
19                         return 1;
20
21                 if (it.test != 3)
22                         return 2;
23
24                 a = 1;
25                 b = Interlocked.Add (ref a, 1);
26                 if (a != 2)
27                         return 3;
28                 if (b != 2)
29                         return 4;
30
31                 /* long */
32                 it.ltest = 2;
33                 int lc = Interlocked.Add (ref it.ltest, 1);
34                 if (lc != 3)
35                         return 5;
36
37                 if (it.ltest != 3)
38                         return 6;
39
40                 la = 1;
41                 lb = Interlocked.Add (ref la, 1);
42                 if (la != 2)
43                         return 7;
44                 if (lb != 2)
45                         return 8;
46
47                 /* Generics */
48                 InterlockTest o1 = new InterlockTest ();
49                 InterlockTest o2 = new InterlockTest ();
50                 InterlockTest o = o1;
51
52                 InterlockTest o3 = Interlocked.CompareExchange (ref o, o2, o2);
53                 if (o3 != o1)
54                         return 9;
55                 if (o != o1)
56                         return 10;
57
58                 InterlockTest o4 = Interlocked.CompareExchange (ref o, o2, o1);
59                 if (o4 != o1)
60                         return 11;
61                 if (o != o2)
62                         return 12;
63
64                 Console.WriteLine ("done!");
65
66                 return 0;
67         }
68 }