Index: trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp	(revision 25602)
+++ trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp	(revision 25603)
@@ -1128,4 +1128,34 @@
 
 /**
+ * Verifies the deadlock stack before calling it a deadlock.
+ *
+ * @retval  VERR_SEM_LV_DEADLOCK if it's a deadlock.
+ * @retval  VERR_TRY_AGAIN if something changed.
+ *
+ * @param   pStack              The deadlock detection stack.
+ */
+static int rtLockValidatorDdVerifyDeadlock(PRTLOCKVALIDATORDDSTACK pStack)
+{
+    uint32_t const c = pStack->c;
+    for (uint32_t iPass = 0; iPass < 3; iPass++)
+    {
+        for (uint32_t i = 1; i < c; i++)
+        {
+            PRTTHREADINT pThread = pStack->a[i].pThread;
+            if (pThread->u32Magic != RTTHREADINT_MAGIC)
+                return VERR_TRY_AGAIN;
+            if (rtThreadGetState(pThread) != pStack->a[i].enmState)
+                return VERR_TRY_AGAIN;
+            if (rtLockValidatorReadRecUnionPtr(&pThread->LockValidator.pRec) != pStack->a[i].pFirstSibling)
+                return VERR_TRY_AGAIN;
+        }
+        RTThreadYield();
+    }
+
+    return VERR_SEM_LV_DEADLOCK;
+}
+
+
+/**
  * Checks for stack cycles caused by another deadlock before returning.
  *
@@ -1191,5 +1221,9 @@
  * detection.
  *
- * @returns Same as rtLockValidatorDeadlockDetection.
+ * @retval  VINF_SUCCESS
+ * @retval  VERR_SEM_LV_DEADLOCK
+ * @retval  VERR_SEM_LV_EXISTING_DEADLOCK
+ * @retval  VERR_TRY_AGAIN
+ *
  * @param   pStack          The stack to use.
  * @param   pOriginalRec    The original record.
@@ -1213,5 +1247,5 @@
          * Process the current record.
          */
-        /* Extract the (next) thread. */
+        /* Find the next relevan owner thread. */
         PRTTHREADINT pNextThread;
         switch (pRec->Core.u32Magic)
@@ -1224,4 +1258,5 @@
                     &&  pNextThread != pThreadSelf)
                     pNextThread = NIL_RTTHREAD;
+
                 if (    pNextThread == NIL_RTTHREAD
                     &&  pRec->Excl.pSibling
@@ -1268,16 +1303,20 @@
                         {
                             pNextThread = rtLockValidatorReadThreadHandle(&pEntry->hThread);
-                            if (    pNextThread
-                                &&  !RTTHREAD_IS_SLEEPING(pNextThread->enmState)
-                                &&  pNextThread != pThreadSelf)
+                            if (pNextThread)
+                            {
+                                if (   pNextThread->u32Magic == RTTHREADINT_MAGIC
+                                    && RTTHREAD_IS_SLEEPING(pNextThread->enmState))
+                                    break;
                                 pNextThread = NIL_RTTHREAD;
+                            }
                         }
                         else
                             Assert(!pEntry || pEntry->Core.u32Magic == RTLOCKVALIDATORSHAREDONE_MAGIC_DEAD);
                     }
+                    if (pNextThread == NIL_RTTHREAD)
+                        break;
                 }
 
                 /* Advance to the next sibling, if any. */
-                Assert(pNextThread == NIL_RTTHREAD);
                 if (   pRec->Shared.pSibling != NULL
                     && pRec->Shared.pSibling != pFirstSibling)
@@ -1302,5 +1341,5 @@
         }
 
-        /* Is that thread waiting for something? */
+        /* If we found a thread, check if it is still waiting for something. */
         RTTHREADSTATE               enmNextState = RTTHREADSTATE_RUNNING;
         PRTLOCKVALIDATORRECUNION    pNextRec     = NULL;
@@ -1338,5 +1377,5 @@
 
             if (RT_UNLIKELY(pNextThread == pThreadSelf))
-                return VERR_SEM_LV_DEADLOCK;
+                return rtLockValidatorDdVerifyDeadlock(pStack);
 
             pRec            = pNextRec;
@@ -1457,6 +1496,23 @@
     RTLOCKVALIDATORDDSTACK Stack;
     int rc = rtLockValidatorDdDoDetection(&Stack, pRec, pThreadSelf);
-    if (RT_FAILURE(rc))
-        rcLockValidatorDoDeadlockComplaining(&Stack, pThreadSelf, pSrcPos, rc);
+    if (RT_SUCCESS(rc))
+        return VINF_SUCCESS;
+
+    if (rc == VERR_TRY_AGAIN)
+    {
+        for (uint32_t iLoop = 0; ; iLoop++)
+        {
+            rc = rtLockValidatorDdDoDetection(&Stack, pRec, pThreadSelf);
+            if (RT_SUCCESS_NP(rc))
+                return VINF_SUCCESS;
+            if (rc != VERR_TRY_AGAIN)
+                break;
+            RTThreadYield();
+            if (iLoop >= 3)
+                return VINF_SUCCESS;
+        }
+    }
+
+    rcLockValidatorDoDeadlockComplaining(&Stack, pThreadSelf, pSrcPos, rc);
     return rc;
 #else
