3 using System.Collections.Concurrent;
4 using System.Threading;
8 static TestTimeout timeout;
10 public static void Main ()
14 TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 60 : 1));
16 Thread gcThread = new Thread (() => {
17 while (timeout.HaveTimeLeft) {
26 // Create threads then join them for 1 seconds (120 for stress tests) nonstop while GCs occur once per ms
27 while (timeout.HaveTimeLeft) {
28 BlockingCollection<Thread> threads = new BlockingCollection<Thread> (new ConcurrentQueue<Thread> (), 128);
30 Thread joinThread = new Thread (() => {
31 for (int i = 0; ; ++i) {
32 Thread t = threads.Take ();
37 // Uncomment this and run with MONO_LOG_LEVEL=info MONO_LOG_MASK=gc
38 // to see GC/join balance in real time
39 //Console.Write ("*");
44 const int makeThreads = 10*1000;
45 for (int i = 0; i < makeThreads; ++i) {
46 Thread t = new Thread (() => { Thread.Yield (); });
55 joinCount += makeThreads;
56 Console.WriteLine("Performed {0} GCs, created {1} threads. Finished? {2}", gcCount, joinCount, !timeout.HaveTimeLeft);