From c0e169b52acd858ef9327858699487d7668a33b4 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Tue, 15 Jun 2021 19:21:55 +0800 Subject: [PATCH] Lock the CRITICAL_SECTION before unlocking it --- Python/condvar.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/condvar.h b/Python/condvar.h index 8cba19b84612dc..80f071ada4dc23 100644 --- a/Python/condvar.h +++ b/Python/condvar.h @@ -162,13 +162,13 @@ _PyCOND_WAIT_MS(PyCOND_T *cv, PyMUTEX_T *cs, DWORD ms) { DWORD wait; cv->waiting++; - PyMUTEX_UNLOCK(cs); + PyMUTEX_LOCK(cs); /* "lost wakeup bug" would occur if the caller were interrupted here, * but we are safe because we are using a semaphore which has an internal * count. */ wait = WaitForSingleObjectEx(cv->sem, ms, FALSE); - PyMUTEX_LOCK(cs); + PyMUTEX_UNLOCK(cs); if (wait != WAIT_OBJECT_0) --cv->waiting; /* Here we have a benign race condition with PyCOND_SIGNAL.