static public int count = 0;
~P () {
- T.finalized = true;
- Thread.Sleep (1000);
// Console.WriteLine ("finalizer done");
count++;
}
}
class T {
-
- static public bool finalized = false;
-
- static void makeP () {
- P p = new P ();
- p = null;
- }
-
static int Main () {
- var t = new Thread (makeP);
- t.Start ();
- t.Join ();
-
- 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;
}
}