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