Remove allocations from Dns.* (dotnet/corefx#41061)
[mono-project.git] / mono / tests / threads-leak.cs
blobf91b72acb31d146a1e5ba4b9b3e2f206d8f5098f
1 using System;
2 using System.Threading;
4 class Driver
6 static ManualResetEvent mre = new ManualResetEvent (false);
8 class MyClassInThread
10 public int I { get; set; }
12 ~MyClassInThread()
14 try {
15 Console.WriteLine($"Finalizer {I}");
16 } catch (NotSupportedException) {
19 mre.Set ();
23 public static void Main(string[] args)
25 for (int i = 0; i < 50; ++i) {
26 SpawnThread(i);
27 GC.Collect();
28 GC.Collect();
29 GC.Collect();
30 GC.Collect();
31 GC.WaitForPendingFinalizers();
32 Console.WriteLine($"Loop {i}");
35 if (!mre.WaitOne(0))
36 Environment.Exit (1);
39 static void SpawnThread(int i)
41 var th = new Thread(_ => {}) { IsBackground = true, };
42 th.Start(new MyClassInThread { I = i });
43 th.Join();