Merge pull request #1720 from blucz/master
[mono.git] / mono / tests / finalizer-wait.cs
index 5720bc1cd415731d1bbe826301f8cd0c2768b102..dde31cbc345b5c5bc1adff7db1d8959454b7234b 100644 (file)
@@ -6,42 +6,25 @@ class P {
 
        static public int count = 0;
        ~P () {
-               T.finalized = true;
-               Thread.Sleep (1000);
-               //Console.WriteLine ("finalizer done");
+               // Console.WriteLine ("finalizer done");
                count++;
        }
 }
 
 class T {
-
-       static public bool finalized = false;
-
-       static void makeP () {
-               P p = new P ();
-               p = null;
-       }
-
-       static void callMakeP (int i) {
-               if (i <= 0)
-               {
-                       makeP ();
-                       return;
-               }
-               callMakeP (i - 1);
-       }
-
        static int Main () {
-               callMakeP (100);
-
-               GC.Collect ();
-               while (!finalized) {
-                       Thread.Sleep (100);
+               for (int i = 0; i < 1000; ++i) {
+                       var t = new Thread (() => {
+                                       P p = new P ();
+                               });
+                       t.Start ();
+                       t.Join ();
+
+                       GC.Collect ();
+                       GC.WaitForPendingFinalizers ();
+                       if (P.count != i + 1)
+                               return 1;
                }
-               GC.WaitForPendingFinalizers ();
-
-               if (P.count == 0)
-                       return 1;
                return 0;
        }
 }