[netcore] Ongoing work. (#13391)
[mono-project.git] / mono / tests / gc-altstack.cs
blob4b3f431467fad705d9afb10b9e7370f6387efea6
1 using System;
2 using System.Threading;
3 using System.Linq;
5 public class Tests
7 static bool finished = false;
9 static void fault () {
10 while (!finished) {
11 object o = null;
12 try {
13 o.ToString ();
14 } catch {
19 static void gc (int niter) {
20 int i = 0;
21 while (i < niter) {
22 i ++;
23 if (i % 100 == 0)
24 Console.Write (".");
25 GC.Collect ();
27 finished = true;
28 Console.WriteLine ();
31 static void test (bool main, int niter) {
32 finished = false;
34 if (main) {
35 var t = new Thread (delegate () {
36 gc (niter);
37 });
38 t.Start ();
40 fault ();
41 } else {
42 var t = new Thread (delegate () {
43 fault ();
44 });
45 t.Start ();
47 gc (niter);
51 public static void Main (String[] args) {
52 /* Test for running a GC while executing a SIGSEGV handler on an altstack */
53 int niter;
55 if (args.Length > 0)
56 niter = Int32.Parse (args [0]);
57 else
58 niter = 1000;
60 test (false, niter);
61 test (true, niter);