Fix race in test waitone1 (#18085)
authorSteve MacLean <sdmaclea.qdt@qualcommdatacenter.com>
Wed, 23 May 2018 08:57:42 +0000 (04:57 -0400)
committerKoundinya Veluri <kouvel@users.noreply.github.com>
Wed, 23 May 2018 08:57:42 +0000 (01:57 -0700)
tests/src/baseservices/threading/mutex/misc/waitone1.cs

index 40f144b..d5a0c5c 100644 (file)
@@ -100,7 +100,7 @@ public class MutexWaitOne1
                 thread = new Thread(new ThreadStart(NeverReleaseMutex));
                 thread.Start();
 
-                Thread.Sleep(100);
+                thread.Join();
                 m_Mutex.WaitOne();
 
                 TestLibrary.TestFramework.LogError("101", "AbandonedMutexException is not thrown if a thread exited without releasing a mutex");
@@ -115,13 +115,6 @@ public class MutexWaitOne1
                 TestLibrary.TestFramework.LogInformation(e.StackTrace);
                 retVal = false;
             }
-            finally
-            {
-                if (null != thread)
-                {
-                    thread.Join();
-                }
-            }
         }
 
         return retVal;
@@ -141,7 +134,7 @@ public class MutexWaitOne1
             thread = new Thread(new ThreadStart(DisposeMutex));
             thread.Start();
 
-            Thread.Sleep(c_DEFAULT_SLEEP_TIME);
+            thread.Join();
             m_Mutex.WaitOne();
 
             TestLibrary.TestFramework.LogError("103", "ObjectDisposedException is not thrown if current instance has already been disposed");
@@ -158,11 +151,6 @@ public class MutexWaitOne1
         }
         finally
         {
-            if (null != thread)
-            {
-                thread.Join();
-            }
-
             if (null != m_Mutex)
             {
                 ((IDisposable)m_Mutex).Dispose();