[System] Fixes UdpClient.Receive with IPv6 endpoint
[mono.git] / mono / tests / sgen-new-threads-dont-join-stw.cs
1 using System;
2 using System.Timers;
3 using System.Threading;
4 using System.Collections;
5 using System.Collections.Generic;
6
7 class T {
8
9     static int count = 0;
10     static object count_lock = new object();
11
12     const long N = 500000;
13     const int num_threads = 8;
14
15     static void UseMemory () {
16         
17         for (int i = 0; i < N; ++i) {
18
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));
27         }
28        
29         
30         lock (count_lock)
31         {
32             count++;
33             Monitor.PulseAll(count_lock);
34         }
35     }
36
37     static void Timer_Elapsed(object sender, EventArgs e)
38     {
39         HashSet<string> h = new HashSet<string>();
40         for (int j = 0; j < 10000; j++)
41         {
42             h.Add(""+j+""+j);
43         }
44     }
45
46     static void Main (string[] args) {
47         
48         for (int j = 0; j < 2; j++)
49         {
50             count = 0;
51
52             List<Thread> threads = new List<Thread>();
53             List<System.Timers.Timer> timers = new List<System.Timers.Timer>();
54
55             for (int i = 0; i < num_threads; i++)
56             {
57                 Thread t3 = new Thread (delegate () { 
58                     UseMemory();
59                     });
60
61                 t3.Start ();
62
63                 System.Timers.Timer timer = new System.Timers.Timer();
64                 timer.Elapsed += Timer_Elapsed;
65                 timer.AutoReset = false;
66                 timer.Interval = 1000;
67                 timer.Start();
68                 timers.Add(timer);
69             }
70             
71             for (int i = 0; i < 4000; i++)
72             {
73                 System.Timers.Timer timer = new System.Timers.Timer();
74                 timer.Elapsed += Timer_Elapsed;
75                 timer.AutoReset = false;
76                 timer.Interval = 500;
77                 timer.Start();
78                 timers.Add(timer);
79             }
80
81             lock (count_lock)
82             {
83                 while (count < num_threads)
84                 {
85                     Monitor.Wait(count_lock);
86                 }
87             }
88
89             foreach (var t in threads)
90             {
91                 t.Join();
92             }
93         }
94     }
95 }