Skip to content

Commit 841b748

Browse files
authored
gh-143424: Fix assertion in _PyMutex_LockTimed (gh-143439)
The assertion doesn't necessarily hold for `threading.Lock`, so allow the lock to be unlocked if `_PY_LOCK_PYTHONLOCK` is set on the flags.
1 parent d745b60 commit 841b748

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Python/lock.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
124124
&entry, (flags & _PY_LOCK_DETACH) != 0);
125125
if (ret == Py_PARK_OK) {
126126
if (entry.handed_off) {
127-
// We own the lock now.
128-
assert(_Py_atomic_load_uint8_relaxed(&m->_bits) & _Py_LOCKED);
127+
// We own the lock now. thread.Lock allows other threads
128+
// to concurrently release the lock so we cannot assert that
129+
// it is locked if _PY_LOCK_PYTHONLOCK is set.
130+
assert(_Py_atomic_load_uint8_relaxed(&m->_bits) & _Py_LOCKED ||
131+
(flags & _PY_LOCK_PYTHONLOCK) != 0);
129132
return PY_LOCK_ACQUIRED;
130133
}
131134
}

0 commit comments

Comments
 (0)