2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / tests / dataslot.cs
1
2 using System;
3 using System.Threading;
4
5 public class Test {
6         static LocalDataStoreSlot[] slot = new LocalDataStoreSlot[102400];
7         
8         private void Thread_func() {
9                 Console.WriteLine("In a thread!");
10
11                 for(int i=51200; i<102400; i++) {
12                         slot[i]=Thread.AllocateDataSlot();
13                         Thread.SetData(slot[i], i);
14                 }
15
16                 Thread.Sleep(5000);
17
18                 Thread.SetData(slot[11111], 42);
19                 Thread.SetData(slot[76801], 42);
20
21                 Thread.Sleep(20000);
22                 
23                 Console.WriteLine("Subthread done");
24                 Console.WriteLine("slot 11111 contains " + Thread.GetData(slot[11111]));
25                 Console.WriteLine("slot 26801 contains " + Thread.GetData(slot[26801]));
26                 Console.WriteLine("slot 76801 contains " + Thread.GetData(slot[76801]));
27                 Console.WriteLine("slot 96801 contains " + Thread.GetData(slot[96801]));
28         }
29
30         public static int Main () {
31                 Console.WriteLine ("Hello, World!");
32                 Test test=new Test();
33                 Thread thr=new Thread(new ThreadStart(test.Thread_func));
34                 thr.Start();
35
36                 for(int i=0; i<51200; i++) {
37                         slot[i]=Thread.AllocateDataSlot();
38                         Thread.SetData(slot[i], i);
39                 }
40                 Thread.SetData(slot[11111], 69);
41                 Thread.SetData(slot[26801], 69);
42
43                 Thread.Sleep(10000);
44                 
45                 Console.WriteLine("Main thread done");
46                 Console.WriteLine("slot 11111 contains " + Thread.GetData(slot[11111]));
47                 Console.WriteLine("slot 16801 contains " + Thread.GetData(slot[16801]));
48                 Console.WriteLine("slot 26801 contains " + Thread.GetData(slot[26801]));
49                 Console.WriteLine("slot 76801 contains " + Thread.GetData(slot[76801]));
50
51                 return 0;
52         }
53 }
54