fix: notify_all on lock timeout to wake blocked readers
When acquire_write or acquire_read times out, call notify_all() before returning False so waiters blocked by the timed-out thread's presence (e.g. readers blocked by writer-preference _writers_waiting > 0) are woken immediately instead of sleeping until the next external notify.
This commit is contained in:
@@ -504,6 +504,7 @@ class _ReadWriteLock:
|
||||
if deadline is not None:
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
self._cond.notify_all()
|
||||
return False
|
||||
self._cond.wait(timeout=remaining)
|
||||
else:
|
||||
@@ -533,6 +534,7 @@ class _ReadWriteLock:
|
||||
if deadline is not None:
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
self._cond.notify_all()
|
||||
return False
|
||||
self._cond.wait(timeout=remaining)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user