Merge pull request #1051 from josedonizetti/bug11916-DataContractSerializer
[mono.git] / mono / tests / finalizer-wait.cs
1 using System;
2 using System.Threading;
3 using System.Runtime.ConstrainedExecution;
4
5 class P {
6
7         static public int count = 0;
8         ~P () {
9                 T.finalized = true;
10                 Thread.Sleep (1000);
11                 // Console.WriteLine ("finalizer done");
12                 count++;
13         }
14 }
15
16 class T {
17
18         static public bool finalized = false;
19
20         static void makeP () {
21                 P p = new P ();
22                 p = null;
23         }
24
25         static int Main () {
26                 var t = new Thread (makeP);
27                 t.Start ();
28                 t.Join ();
29
30                 GC.Collect ();
31                 while (!finalized) {
32                         Thread.Sleep (100);
33                 }
34                 GC.WaitForPendingFinalizers ();
35
36                 if (P.count == 0)
37                         return 1;
38                 return 0;
39         }
40 }