Reduce TLS accesses. (#11487)
[mono-project.git] / mono / tests / finalizer-thread.cs
blobafcbaf1a3659cf9d86fcce3603e4d42f4ec896ff
2 using System;
3 using System.Collections;
4 using System.Threading;
6 public class foo {
7 public static LocalDataStoreSlot dataslot = Thread.AllocateDataSlot();
8 public static int final_count=0;
10 ~foo() {
11 // Demonstrate that this is still the same thread
12 string ID=(string)Thread.GetData(dataslot);
13 if(ID==null) {
14 Console.WriteLine("Set ID: foo");
15 Thread.SetData(dataslot, "foo");
18 // Don't run forever
19 if(final_count++>10) {
20 Environment.Exit(0);
23 Console.WriteLine("finalizer thread ID: {0}", (string)Thread.GetData(dataslot));
25 if ((string)Thread.GetData(dataslot) != "foo")
26 throw new Exception ();
29 public static int Main() {
30 ArrayList list = new ArrayList ();
31 Thread.SetData(dataslot, "ID is wibble");
32 Environment.ExitCode = 2;
33 while(true) {
34 foo instance = new foo();
35 list.Add (new WeakReference(instance));
36 Thread.Sleep (0);
38 return 1;