3 using System.Threading;
6 static LocalDataStoreSlot slot;
8 private void Thread_func() {
9 //Throws undocumented exception :-(
10 //LocalDataStoreSlot namedslot=Thread.AllocateNamedDataSlot("data-slot");
11 LocalDataStoreSlot namedslot=Thread.GetNamedDataSlot("data-slot");
13 Console.WriteLine("In a thread!");
15 Thread thr=Thread.CurrentThread;
16 Console.WriteLine("Found thread!");
18 Thread otherthr=Thread.CurrentThread;
19 Console.WriteLine("Other subthread is " + otherthr.Name);
21 Thread.SetData(slot, thr);
22 Thread storedthr=(Thread)Thread.GetData(slot);
23 Console.WriteLine("Stored subthread is " + storedthr.Name);
25 Thread.SetData(namedslot, thr);
26 storedthr=(Thread)Thread.GetData(namedslot);
27 Console.WriteLine("Stored subthread is " + storedthr.Name);
29 Console.WriteLine("Locking thr for 1.5s");
34 Console.WriteLine("Waiting for signal");
37 Console.WriteLine("Thread signalled!");
40 Console.WriteLine("Sleeping for 10s");
43 Thread storedthr2=(Thread)Thread.GetData(slot);
44 Console.WriteLine("Stored subthread is still " + storedthr2.Name);
47 public static int Main () {
48 Console.WriteLine ("Hello, World!");
49 slot=Thread.AllocateDataSlot();
50 LocalDataStoreSlot namedslot=Thread.AllocateNamedDataSlot("data-slot");
52 Test test = new Test();
53 Thread thr=new Thread(new ThreadStart(test.Thread_func));
56 Thread main=Thread.CurrentThread;
58 Thread othermain=Thread.CurrentThread;
59 Console.WriteLine("Other name " + othermain.Name);
62 Console.WriteLine("In the main line!");
64 Console.WriteLine("Trying to enter lock");
65 if(Monitor.TryEnter(thr, 100)==true) {
66 Console.WriteLine("Returned lock");
69 Console.WriteLine("Didn't get lock");
72 Thread.SetData(slot, main);
73 Thread storedthr=(Thread)Thread.GetData(slot);
74 Console.WriteLine("Stored subthread is " + storedthr.Name);
76 Thread.SetData(namedslot, main);
77 storedthr=(Thread)Thread.GetData(namedslot);
78 Console.WriteLine("Stored subthread is " + storedthr.Name);
81 Console.WriteLine("Joined thread");
83 Console.WriteLine("Didn't join thread");
88 Console.WriteLine("Signalled thread");