[System.ServiceModel] Prevent crash in Dispatcher.ListenerLoopManager… (#7136)
[mono-project.git] / mono / tests / bug-18026.cs
blob85a823481aa21c0270ae94d993fa5a0062870e24
1 using System;
2 using System.Threading;
4 public class Test
6 static bool done = false;
8 static void Allocator (int n)
10 //Console.WriteLine (n);
11 if (n < 1)
13 done = true;
14 return;
17 for (int i = 0; i < 10000; ++i)
19 var o = new object [12];
20 o = null;
22 ThreadPool.QueueUserWorkItem (_ => Allocator (n - 1));
25 static void LowLimits ()
27 ThreadPool.SetMinThreads (1, 1);
28 ThreadPool.SetMaxThreads (1, 1);
31 static void HighLimits ()
33 ThreadPool.SetMaxThreads (1000, 1000);
34 ThreadPool.SetMinThreads (100, 100);
37 public static void Main ()
39 var N = 10;
40 var dones = new bool [N];
41 var low = false;
43 ThreadPool.QueueUserWorkItem (_ => Allocator (10000));
44 while (!done)
46 //Console.WriteLine ("new");
47 if (low)
48 LowLimits ();
49 else
50 HighLimits ();
51 low = !low;
53 for (int i = 0; i < N; ++i)
55 var j = i;
56 dones [j] = false;
57 ThreadPool.QueueUserWorkItem (_ => {
58 //Console.WriteLine ("done " + j);
59 Thread.Sleep (1);
60 dones [j] = true;
61 });
64 bool all_done;
67 all_done = true;
68 for (int i = 0; i < N; ++i)
70 if (!dones [i])
72 all_done = false;
73 Thread.Sleep (1);
74 break;
77 } while (!all_done);