Merge branch 'master' of github.com:tgiphil/mono
[mono.git] / mono / tests / threadpool.cs
1 using System;
2 using System.Threading;
3
4 public class Test {
5
6         static int csum = 0;
7         
8         public static void test_callback (object state) {
9                 Console.WriteLine("test_casllback:" + state);
10                 Thread.Sleep (200);
11                 Interlocked.Increment (ref csum);
12         }
13         
14         public static int Main () {
15                 int workerThreads;
16                 int completionPortThreads;
17                 
18                 ThreadPool.GetMaxThreads (out workerThreads, out completionPortThreads);
19                 Console.WriteLine ("workerThreads: {0} completionPortThreads: {1}", workerThreads, completionPortThreads);
20                 
21                 ThreadPool.GetAvailableThreads (out workerThreads, out completionPortThreads);
22                 Console.WriteLine ("workerThreads: {0} completionPortThreads: {1}", workerThreads, completionPortThreads);
23
24                 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST1");
25                 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST2");
26                 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST3");
27                 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST4");
28                 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback), "TEST5");
29                 ThreadPool.QueueUserWorkItem (new WaitCallback (test_callback));
30
31                 while (csum < 6) {
32                         Thread.Sleep (100);
33                 }
34
35                 Console.WriteLine ("CSUM: " + csum);
36
37                 if (csum != 6)
38                         return 1;
39
40                 return 0;
41         }
42 }
43