using System;
using System.Threading;
-using System.Collections;
-
-class T {
+using System.Linq;
+public class Tests
+{
static bool finished = false;
- static void segv () {
- while (true) {
- if (finished)
- break;
+ static void fault () {
+ while (!finished) {
+ object o = null;
try {
- object o = null;
o.ToString ();
- } catch (NullReferenceException) {
+ } catch {
}
}
}
- static void Main (string[] args) {
- /* Test for running a GC while executing a SIGSEGV handler on an altstack */
- Thread t = new Thread (delegate () {
- segv ();
- });
+ static void gc (int niter) {
+ int i = 0;
+ while (i < niter) {
+ i ++;
+ if (i % 100 == 0)
+ Console.Write (".");
+ GC.Collect ();
+ }
+ finished = true;
+ Console.WriteLine ();
+ }
+
+ static void test (bool main, int niter) {
+ finished = false;
- t.Start ();
+ if (main) {
+ var t = new Thread (delegate () {
+ gc (niter);
+ });
+ t.Start ();
- for (int i = 0; i < 100000; ++i) {
- new ArrayList ();
+ fault ();
+ } else {
+ var t = new Thread (delegate () {
+ fault ();
+ });
+ t.Start ();
+
+ gc (niter);
}
+ }
- finished = true;
+ public static void Main (String[] args) {
+ /* Test for running a GC while executing a SIGSEGV handler on an altstack */
+ int niter;
+
+ if (args.Length > 0)
+ niter = Int32.Parse (args [0]);
+ else
+ niter = 1000;
- t.Join ();
+ test (false, niter);
+ test (true, niter);
}
}