Reduce TLS accesses. (#11487)
[mono-project.git] / mono / tests / xdomain-threads.cs
blobf2c5cd97fc24e1470db502d298392b3bfd9ebf5a
1 using System;
2 using System.Threading;
3 using System.Runtime.Remoting;
5 // Does a foreign domain's thread object persist (in .NET) even if it
6 // hasn't been started?
7 //
8 // Insubstantial, because it can't be "moved" to another domain.
10 // Can we start a foreign domain's thread (i.e. does the thread then
11 // switch to the foreign domain and execute the start method there)?
13 // No, we can't start it from another domain, because we can't bring
14 // to another domain.
16 // What if we start a foreign domain's thread if the domain is gone?
18 // See above.
20 public class Test : MarshalByRefObject {
21 public Thread thread;
22 public String str;
24 public void setThread () {
25 Console.WriteLine ("setting thread");
26 thread = Thread.CurrentThread;
27 thread.Name = "foo";
30 public void setStr (string s) {
31 Console.WriteLine ("setting str");
32 str = s;
35 public void callSetThread (Test t) {
36 Thread thread = new Thread (new ThreadStart (t.setThread));
38 thread.Start ();
39 thread.Join ();
41 t.setStr ("a" + "b");
45 public class main {
46 public static int Main (string [] args) {
47 AppDomain domain = AppDomain.CreateDomain ("newdomain");
48 Test myTest = new Test ();
49 Test otherTest = (Test) domain.CreateInstanceAndUnwrap (typeof (Test).Assembly.FullName, typeof (Test).FullName);
51 otherTest.callSetThread (myTest);
53 if (myTest.thread.GetType () == Thread.CurrentThread.GetType ())
54 Console.WriteLine ("same type");
55 else {
56 Console.WriteLine ("different type");
57 return 1;
60 AppDomain.Unload (domain);
62 GC.Collect ();
63 GC.WaitForPendingFinalizers ();
65 Console.WriteLine ("thread " + myTest.thread);
67 Console.WriteLine ("str " + myTest.str);
69 if (!myTest.thread.Name.Equals("foo"))
70 return 1;
72 return 0;