[runtime] Require C# namespace to be quoted.
[mono-project.git] / mono / tests / sgen-new-threads-dont-join-stw.cs
blob966fff5d5b7e0b78ed964690f85846fe68e28f05
1 using System;
2 using System.Timers;
3 using System.Threading;
4 using System.Collections;
5 using System.Collections.Generic;
7 class T {
9 static int count = 0;
10 static object count_lock = new object();
12 const long N = 500000;
13 const int num_threads = 8;
15 static void UseMemory () {
17 for (int i = 0; i < N; ++i) {
19 var l1 = new ArrayList ();
20 l1.Add(""+i);
21 var l2 = new ArrayList ();
22 l2.Add(""+(i+1));
23 var l3 = new ArrayList ();
24 l3.Add(""+(i+2));
25 var l4 = new ArrayList ();
26 l4.Add(""+(i+3));
30 lock (count_lock)
32 count++;
33 Monitor.PulseAll(count_lock);
37 static void Timer_Elapsed(object sender, EventArgs e)
39 HashSet<string> h = new HashSet<string>();
40 for (int j = 0; j < 10000; j++)
42 h.Add(""+j+""+j);
46 static void Main (string[] args) {
47 var testTimeout = new TestTimeout ();
48 testTimeout.Start ();
50 const int TOTAL_ITERATIONS = 2;
51 for (int j = 0; j < TOTAL_ITERATIONS; j++)
53 count = 0;
55 List<Thread> threads = new List<Thread>();
56 List<System.Timers.Timer> timers = new List<System.Timers.Timer>();
58 for (int i = 0; i < num_threads; i++)
60 Thread t3 = new Thread (delegate () {
61 UseMemory();
62 });
64 t3.Start ();
66 System.Timers.Timer timer = new System.Timers.Timer();
67 timer.Elapsed += Timer_Elapsed;
68 timer.AutoReset = false;
69 timer.Interval = 1000;
70 timer.Start();
71 timers.Add(timer);
74 for (int i = 0; i < 4000; i++)
76 System.Timers.Timer timer = new System.Timers.Timer();
77 timer.Elapsed += Timer_Elapsed;
78 timer.AutoReset = false;
79 timer.Interval = 500;
80 timer.Start();
81 timers.Add(timer);
84 lock (count_lock)
86 while (count < num_threads)
88 Console.Write (".");
89 Monitor.Wait(count_lock);
93 foreach (var t in threads)
95 t.Join();
98 Console.WriteLine ();
99 if (!testTimeout.HaveTimeLeft ()) {
100 var finishTime = DateTime.UtcNow;
101 var ranFor = finishTime - testTimeout.StartTime;
102 Console.WriteLine ("Will run out of time soon. ran for {0}, finished {1}/{2} iterations", ranFor, j+1, TOTAL_ITERATIONS);
106 Console.WriteLine ("done");