Skip to content

Commit 2f5c90a

Browse files
committed
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.
1 parent 78825e0 commit 2f5c90a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Modules/_multiprocessing/semaphore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self)
191191
assert(self->count == 1);
192192
}
193193

194+
--self->count;
194195
if (!ReleaseSemaphore(self->handle, 1, NULL)) {
195196
if (GetLastError() == ERROR_TOO_MANY_POSTS) {
196197
PyErr_SetString(PyExc_ValueError, "semaphore or lock "
@@ -201,7 +202,6 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self)
201202
}
202203
}
203204

204-
--self->count;
205205
Py_RETURN_NONE;
206206
}
207207

@@ -437,10 +437,10 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self)
437437
#endif
438438
}
439439

440+
--self->count;
440441
if (sem_post(self->handle) < 0)
441442
return PyErr_SetFromErrno(PyExc_OSError);
442443

443-
--self->count;
444444
Py_RETURN_NONE;
445445
}
446446

0 commit comments

Comments
 (0)