New test.
[mono.git] / mono / tests / thread-static.cs
1 using System;
2 using System.Threading;
3
4 class T {
5         [ThreadStatic]
6         static int var = 5;
7
8         static bool tfailed = true;
9
10         static void thread () {
11                 tfailed = false;
12                 if (var != 0)
13                         tfailed = true;
14                 Console.WriteLine ("start value: {0}", var);
15                 for (int i = 0; i < 10; ++i) {
16                         var += 10;
17                         Thread.Sleep (5);
18                 }
19                 Console.WriteLine ("end value: {0}", var);
20                 if (var != 100)
21                         tfailed = true;
22         }
23         
24         static int Main () {
25                 bool failed = false;
26                 var  = 10;
27                 Thread thr = new Thread (new ThreadStart (thread));
28                 thr.Start ();
29                 if (var != 10)
30                         failed = true;
31                 var = 20;
32                 Console.WriteLine ("value in main thread: {0}", var);
33                 thr.Join ();
34                 Console.WriteLine ("value in main thread after join: {0}", var);
35                 if (var != 20)
36                         failed = true;
37
38                 if (failed)
39                         return 1;
40                 if (tfailed)
41                         return 2;
42                 return 0;
43         }
44 }