Use __cdecl rather than __stdcall for icalls on Windows 32-bit
[mono.git] / mono / tests / sgen-new-threads-collect.cs
1
2 using System;
3 using System.Collections.Concurrent;
4 using System.Threading;
5
6 class Driver
7 {
8         public static void Main ()
9         {
10                 BlockingCollection<Thread> threads = new BlockingCollection<Thread> (new ConcurrentQueue<Thread> (), 128);
11
12                 bool finished = false;
13
14                 Thread gcThread = new Thread (() => {
15                         while (!finished) {
16                                 GC.Collect ();
17                                 Thread.Yield ();
18                         }
19                 });
20
21                 Thread joinThread = new Thread (() => {
22                         for (int i = 0; ; ++i) {
23                                 Thread t = threads.Take ();
24                                 if (t == null)
25                                         break;
26                                 t.Join ();
27                                 if ((i + 1) % (50) == 0)
28                                         Console.Write (".");
29                                 if ((i + 1) % (50 * 50) == 0)
30                                         Console.WriteLine ();
31                         }
32                 });
33
34                 gcThread.Start ();
35                 joinThread.Start ();
36
37                 for (int i = 0; i < 10 * 1000; ++i) {
38                         Thread t = new Thread (() => { Thread.Yield (); });
39                         t.Start ();
40
41                         threads.Add (t);
42                 }
43
44                 threads.Add (null);
45
46                 joinThread.Join ();
47
48                 finished = true;
49                 gcThread.Join ();
50         }
51 }