3 using System.Collections.Concurrent;
4 using System.Threading;
8 static DateTime targetTime;
9 static bool finished() {
10 DateTime now = DateTime.UtcNow;
11 return now > targetTime;
14 public static void Main ()
18 targetTime = DateTime.UtcNow.AddSeconds(30);
20 Thread gcThread = new Thread (() => {
30 // Create threads then join them for 30 seconds nonstop while GCs occur once per ms
32 BlockingCollection<Thread> threads = new BlockingCollection<Thread> (new ConcurrentQueue<Thread> (), 128);
34 Thread joinThread = new Thread (() => {
35 for (int i = 0; ; ++i) {
36 Thread t = threads.Take ();
41 // Uncomment this and run with MONO_LOG_LEVEL=info MONO_LOG_MASK=gc
42 // to see GC/join balance in real time
43 //Console.Write ("*");
48 const int makeThreads = 10*1000;
49 for (int i = 0; i < makeThreads; ++i) {
50 Thread t = new Thread (() => { Thread.Yield (); });
59 joinCount += makeThreads;
60 Console.WriteLine("Performed {0} GCs, created {1} threads. Finished? {2}", gcCount, joinCount, finished());