[System] Tweak socket test
[mono-project.git] / mono / tests / dataslot.cs
blob15280af496dd884f6821fa2a76f8743892cf0ea7
2 using System;
3 using System.Threading;
5 public class Test : MarshalByRefObject {
6 static LocalDataStoreSlot[] slot = new LocalDataStoreSlot[102400];
8 private void Thread_func() {
9 Console.WriteLine("In a thread!");
11 for(int i=51200; i<102400; i++) {
12 slot[i]=Thread.AllocateDataSlot();
13 Thread.SetData(slot[i], i);
16 Thread.Sleep(5000);
18 Thread.SetData(slot[11111], 42);
19 Thread.SetData(slot[76801], 42);
21 Thread.Sleep(20000);
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]));
30 static LocalDataStoreSlot slot2;
31 static string slot_value;
33 public void Foo (AppDomain ad)
35 ad.DoCallBack (new CrossAppDomainDelegate (Bar));
38 public static void Bar ()
40 slot_value = (string)Thread.GetData (slot2);
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();
49 for(int i=0; i<51200; i++) {
50 slot[i]=Thread.AllocateDataSlot();
51 Thread.SetData(slot[i], i);
53 Thread.SetData(slot[11111], 69);
54 Thread.SetData(slot[26801], 69);
56 Thread.Sleep(10000);
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]));
64 // Test appdomain transitions
65 AppDomain ad = AppDomain.CreateDomain ("MyFriendlyDomain");
66 Test o = (Test) ad.CreateInstanceFromAndUnwrap ("dataslot.exe", "Test");
68 slot2 = Thread.AllocateDataSlot ();
69 Thread.SetData (slot2, "hello");
71 o.Foo (AppDomain.CurrentDomain);
73 if (Test.slot_value != "hello")
74 return 1;
76 return 0;