Reduce TLS accesses. (#11487)
[mono-project.git] / mono / tests / finalizer-exception.cs
blob71f4b4cc20933647e7fcc1df7d36407ec6261ae7
1 using System;
2 using System.Threading;
4 public class FinalizerException {
6 ~FinalizerException () {
7 throw new Exception ();
10 static IntPtr aptr;
13 * We allocate the exception object deep down the stack so
14 * that it doesn't get pinned.
16 public static unsafe void MakeException (int depth) {
17 // Avoid tail calls
18 int* values = stackalloc int [20];
19 aptr = new IntPtr (values);
20 if (depth <= 0) {
21 for (int i = 0; i < 10; i++)
22 new FinalizerException ();
23 return;
25 MakeException (depth - 1);
28 public static int Main () {
29 AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
30 Console.WriteLine ("caught");
31 Environment.Exit (0);
34 var t = new Thread (delegate () { MakeException (1024); });
35 t.Start ();
36 t.Join ();
38 GC.Collect ();
39 GC.WaitForPendingFinalizers ();
41 Thread.Sleep (Timeout.Infinite); // infinite wait so we don't race against the unhandled exception callback
43 return 2;