Correctly handle abandoned mutexes on non-Windows platforms
[mono.git] / mcs / class / corlib / Test / System.Threading / MutexTest.cs
index 5149ece6900f034409ae09a0ef9558d292894388..ee3e58860494f861de1c6acc820572100cd83c4c 100644 (file)
@@ -20,6 +20,7 @@ namespace MonoTests.System.Threading
                {\r
                        public int id;\r
                        public Mutex mut;\r
+                       public bool abandoned_exception;\r
                        public ConcClass(int id,Mutex mut)\r
                        {\r
                                this.id = id;\r
@@ -63,7 +64,12 @@ namespace MonoTests.System.Threading
 \r
                        public void WaitAndForget()\r
                        {\r
-                               this.Wait();\r
+                               try {\r
+                                       this.Wait();\r
+                               } catch (AbandonedMutexException) {\r
+                                       this.abandoned_exception = true;\r
+                               }\r
+\r
                                this.marker = id;\r
                        }\r
                        public void WaitAndWait()\r
@@ -137,7 +143,7 @@ namespace MonoTests.System.Threading
                }\r
 \r
                [Test]\r
-               public void TestWaitAndFoget1()\r
+               public void TestWaitAndForget1()\r
                {\r
                        Mutex Sem = new Mutex(false);\r
                        ConcClassLoop class1 = new ConcClassLoop(1,Sem);\r
@@ -148,9 +154,11 @@ namespace MonoTests.System.Threading
                        try {\r
                                thread1.Start();\r
                                TestUtil.WaitForNotAlive (thread1, "t1");\r
+                               Assert.IsFalse (class1.abandoned_exception, "e1");\r
        \r
                                thread2.Start();\r
                                TestUtil.WaitForNotAlive (thread2, "t2");\r
+                               Assert.IsTrue (class2.abandoned_exception, "e2");\r
                        \r
                                Assert.AreEqual (class2.id, class2.marker);\r
                        } finally {\r