[runtime] Remove all NACL support. It was unmaintained for a long time. (#4955)
[mono.git] / mono / tests / thread6.cs
index efdff2b00fb5eec2342d73b017bdc86fbcc4c9bf..02f1093cd8e83d07bece152b9532b5b8faf2852e 100644 (file)
@@ -170,6 +170,64 @@ public class Tests {
                return 0;
        }
 
+       public static void HasTry ()
+       {
+               try {
+                       throw new Exception ("boop");
+               } catch (Exception e) {
+                       // See if we re-throw the thread abort exception here
+               }
+       }
+
+       public static int test_0_thread_abort_water_mark () 
+       {
+               Boolean failed = true;
+
+               try {
+                       Thread.CurrentThread.Abort ("test_0_thread_abort_water_mark");
+               } catch (ThreadAbortException e) {
+                       HasTry ();
+                       Thread.ResetAbort ();
+                       failed = false;
+               } finally {
+                       if (failed) {
+                               Thread.ResetAbort ();
+                               throw new Exception ("Threw pending ThreadAbort exception under stack threshold");
+                       }
+                       Console.WriteLine ("Working thread abort");
+               }
+
+               return 0;
+       }
+
+       public static int test_0_thread_abort_water_mark_other_exc () 
+       {
+               Boolean failed = true;
+
+               try {
+                       try {
+                               try {
+                                       Thread.CurrentThread.Abort ("TestKeepAbort");
+                               } catch (ThreadAbortException ta_ex) {
+                                       throw new ArgumentNullException("SpecificDummyException");
+                               }
+                       } catch (ArgumentNullException ex){
+                               // Throw ThreadAbortException here
+                       }
+               } catch (ThreadAbortException ex) {
+                       Console.WriteLine ("Retained thread abort exception");
+                       failed = false;
+                       Thread.ResetAbort ();
+               } catch (Exception e) {
+                       failed = true;
+               } finally {
+                       if (failed)
+                               throw new Exception ("Lost the thread abort due to another exception running.");
+               }
+
+               return 0;
+       }
+
        public class CBO : ContextBoundObject {
                public void Run () {
                        Thread.CurrentThread.Abort ("FOO");
@@ -202,10 +260,18 @@ public class Tests {
                // Check that thread abort exceptions originating in another thread are not automatically rethrown
                object o = new object ();
                Thread t = null;
+               bool waiting = false;
                Action a = delegate () {
                        t = Thread.CurrentThread;
-                       lock (o) {
-                               Monitor.Pulse (o);
+                       while (true) {
+                               lock (o) {
+                                       if (waiting) {
+                                               Monitor.Pulse (o);
+                                               break;
+                                       }
+                               }
+
+                               Thread.Sleep (10);
                        }
                        while (true) {
                                Thread.Sleep (1000);
@@ -213,6 +279,7 @@ public class Tests {
                };
                var ar = a.BeginInvoke (null, null);
                lock (o) {
+                       waiting = true;
                        Monitor.Wait (o);
                }