Skip to content

Commit

Permalink
semaphore.c: decrease count before release sem_lock
Browse files Browse the repository at this point in the history
This fixes a hang in test_multiprocessing when running without the GIL
due to lost modifications to count in the seamphore.
  • Loading branch information
colesbury committed Apr 23, 2023
1 parent 78825e0 commit 2f5c90a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Modules/_multiprocessing/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -201,7 +202,6 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self)
}
}

--self->count;
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 2f5c90a

Please sign in to comment.