Reduce TLS accesses. (#11487)
[mono-project.git] / mono / tests / threadpool1.cs
blobea3014a3da727728f703546bdd4c48f0b991c2e9
1 using System;
2 using System.Threading;
4 public class Test {
6 static int csum = 0;
8 public static void test_callback (object state) {
9 int workerThreads;
10 int completionPortThreads;
11 ThreadPool.GetAvailableThreads (out workerThreads, out completionPortThreads);
12 Console.WriteLine("test_casllback:" + state + "ATH: " + workerThreads);
13 Thread.Sleep (10);
15 Interlocked.Increment (ref csum);
18 public static int Main () {
19 int workerThreads;
20 int completionPortThreads;
21 int runs = 10;
23 ThreadPool.GetMaxThreads (out workerThreads, out completionPortThreads);
24 Console.WriteLine ("workerThreads: {0} completionPortThreads: {1}", workerThreads, completionPortThreads);
26 ThreadPool.GetAvailableThreads (out workerThreads, out completionPortThreads);
27 Console.WriteLine ("workerThreads: {0} completionPortThreads: {1}", workerThreads, completionPortThreads);
29 for (int i = 0; i < runs; i++) {
30 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST1 " + i);
31 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST2 " + i);
32 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST3 " + i);
33 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST4 " + i);
34 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST5 " + i);
36 do {
37 ThreadPool.GetAvailableThreads (out workerThreads, out completionPortThreads);
38 if (workerThreads == 0)
39 Thread.Sleep (100);
40 } while (workerThreads == 0);
43 ThreadPool.GetAvailableThreads (out workerThreads, out completionPortThreads);
44 Console.WriteLine ("workerThreads: {0} completionPortThreads: {1}", workerThreads, completionPortThreads);
47 while (csum < (runs * 5)) {
48 Thread.Sleep (100);
52 Console.WriteLine ("CSUM: " + csum);
54 if (csum != (runs * 5))
55 return 1;
57 return 0;