Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / gc-altstack.cs
1 using System;
2 using System.Threading;
3 using System.Linq;
4
5 public class Tests
6 {
7         static bool finished = false;
8
9         static void fault () {
10                 while (!finished) {
11                         object o = null;
12                         try {
13                                 o.ToString ();
14                         } catch {
15                         }
16                 }
17         }
18
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 ();
26                 }
27                 finished = true;
28                 Console.WriteLine ();
29         }
30
31         static void test (bool main, int niter) {
32                 finished = false;
33
34                 if (main) {
35                         var t = new Thread (delegate () {
36                                         gc (niter);
37                                 });
38                         t.Start ();
39
40                         fault ();
41                 } else {
42                         var t = new Thread (delegate () {
43                                         fault ();
44                                 });
45                         t.Start ();
46
47                         gc (niter);
48                 }
49         }
50
51         public static void Main (String[] args) {
52                 /* Test for running a GC while executing a SIGSEGV handler on an altstack */
53                 int niter;
54
55                 if (args.Length > 0)
56                         niter = Int32.Parse (args [0]);
57                 else
58                         niter = 1000;
59
60                 test (false, niter);
61                 test (true, niter);
62         }
63 }
64