[interp] disable assemblyresolve_event6.exe
[mono.git] / mono / tests / dataslot.cs
1
2 using System;
3 using System.Threading;
4
5 public class Test : MarshalByRefObject {
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         static LocalDataStoreSlot slot2;
31         static string slot_value;
32         
33         public void Foo (AppDomain ad)
34         {
35                 ad.DoCallBack (new CrossAppDomainDelegate (Bar));
36         }
37         
38         public static void Bar ()
39         {
40                  slot_value = (string)Thread.GetData (slot2);
41         }
42
43         public static int Main () {
44                 Console.WriteLine ("Hello, World!");
45                 Test test=new Test();
46                 Thread thr=new Thread(new ThreadStart(test.Thread_func));
47                 thr.Start();
48
49                 for(int i=0; i<51200; i++) {
50                         slot[i]=Thread.AllocateDataSlot();
51                         Thread.SetData(slot[i], i);
52                 }
53                 Thread.SetData(slot[11111], 69);
54                 Thread.SetData(slot[26801], 69);
55
56                 Thread.Sleep(10000);
57                 
58                 Console.WriteLine("Main thread done");
59                 Console.WriteLine("slot 11111 contains " + Thread.GetData(slot[11111]));
60                 Console.WriteLine("slot 16801 contains " + Thread.GetData(slot[16801]));
61                 Console.WriteLine("slot 26801 contains " + Thread.GetData(slot[26801]));
62                 Console.WriteLine("slot 76801 contains " + Thread.GetData(slot[76801]));
63
64                 // Test appdomain transitions
65                 AppDomain ad = AppDomain.CreateDomain ("MyFriendlyDomain");
66                 Test o = (Test) ad.CreateInstanceFromAndUnwrap ("dataslot.exe", "Test");
67                 
68                 slot2 = Thread.AllocateDataSlot ();
69                 Thread.SetData (slot2, "hello");
70                 
71                 o.Foo (AppDomain.CurrentDomain);
72
73                 if (Test.slot_value != "hello")
74                         return 1;
75
76                 return 0;
77         }
78 }
79