Reduce TLS accesses. (#11487)
[mono-project.git] / mono / tests / generic-special2.2.cs
blob625d8736599b1af0f1429bc1322d13087cf9ab95
1 using System;
2 using System.Reflection;
3 using System.IO;
4 using System.Collections.Generic;
5 using System.Threading;
7 internal class GenericType<T> {
8 [ThreadStatic]
9 internal static object static_var;
11 public static void AccessStaticVar ()
13 if (static_var != null && static_var.GetType () != typeof (List<T>))
14 throw new Exception ("Corrupted static var");
15 GenericType<T>.static_var = new List<T> ();
19 public static class Program {
20 private static bool stress;
22 /* Create a lot of static vars */
23 private static void CreateVTables ()
25 Type[] nullArgs = new Type[0];
26 Assembly ass = Assembly.GetAssembly (typeof (int));
27 foreach (Type type in ass.GetTypes ()) {
28 try {
29 Type inst = typeof (GenericType<>).MakeGenericType (type);
30 Activator.CreateInstance (inst);
31 } catch {
36 private static void StressStaticFieldAddr ()
38 while (stress) {
39 GenericType<object>.AccessStaticVar ();
43 public static void Main (string[] args)
45 Thread thread = new Thread (StressStaticFieldAddr);
47 stress = true;
48 thread.Start ();
49 CreateVTables ();
50 stress = false;
52 thread.Join ();