Merge pull request #4938 from kumpera/optimize_ref_queries
[mono.git] / mono / tests / test-tls.cs
1 using System;
2 using System.Threading;
3
4 public class Program
5 {
6         public const int nr_threads = 4;
7         public const int reps = 10000;
8         public static int[] allocs = new int[nr_threads];
9
10         public Program (int index)
11         {
12                 allocs [index] += 1;
13         }
14
15         public static void Work (object oindex)
16         {
17                 int index = (int)oindex;
18                 for (int i = 0; i < reps; i++) {
19                         Thread thread = Thread.CurrentThread;
20                         if (string.Compare (thread.Name, "t" + index) == 0)
21                                 new Program (index);
22                 }
23         }
24
25         public static int Main (string[] args)
26         {
27                 Thread[] threads = new Thread[nr_threads];
28
29                 for (int i = 0; i < nr_threads; i++) {
30                         threads [i] = new Thread (Work);
31                         threads [i].Name = "t" + i;
32                         threads [i].Start (i);
33                 }
34
35                 for (int i = 0; i < nr_threads; i++) {
36                         threads [i].Join ();
37                         if (allocs [i] != reps)
38                                 return 1;
39                 }
40
41                 return 0;
42         }
43 }