merge -r 60814:60815
[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         static int s_test;
10         
11         public static int Main() {
12                 int a,b;
13                 long la, lb;
14
15                 InterlockTest it = new InterlockTest ();
16
17                 /* int */
18                 it.test = 2;
19                 int c = Interlocked.Add (ref it.test, 1);
20                 if (c != 3)
21                         return -1;
22
23                 if (it.test != 3)
24                         return -2;
25
26                 a = 1;
27                 b = Interlocked.Add (ref a, 1);
28                 if (a != 2)
29                         return -3;
30                 if (b != 2)
31                         return -4;
32
33                 /* long */
34                 it.ltest = 2;
35                 int lc = Interlocked.Add (ref it.ltest, 1);
36                 if (lc != 3)
37                         return -5;
38
39                 if (it.ltest != 3)
40                         return -6;
41
42                 la = 1;
43                 lb = Interlocked.Add (ref la, 1);
44                 if (la != 2)
45                         return -7;
46                 if (lb != 2)
47                         return -8;
48
49                 Console.WriteLine ("done!");
50
51                 return 0;
52         }
53 }