From 2f5c90a28470a3be8840f30963face67deb86fd3 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Mon, 3 Feb 2020 13:04:44 -0500 Subject: [PATCH] semaphore.c: decrease count before release sem_lock This fixes a hang in test_multiprocessing when running without the GIL due to lost modifications to count in the seamphore. --- Modules/_multiprocessing/semaphore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index 897b8db7110..9bee46fc5b9 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -191,6 +191,7 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self) assert(self->count == 1); } + --self->count; if (!ReleaseSemaphore(self->handle, 1, NULL)) { if (GetLastError() == ERROR_TOO_MANY_POSTS) { PyErr_SetString(PyExc_ValueError, "semaphore or lock " @@ -201,7 +202,6 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self) } } - --self->count; Py_RETURN_NONE; } @@ -437,10 +437,10 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self) #endif } + --self->count; if (sem_post(self->handle) < 0) return PyErr_SetFromErrno(PyExc_OSError); - --self->count; Py_RETURN_NONE; }