Skip to content

Commit d6faff0

Browse files
committed
core: wake Waker outside of lock.
Given: - Broker asleep in poll() - thread B calling Latch.put() Previously, - B takes lock, - B wakes socket by dropping GIL and writing to it - Broker wakes from poll(), acquires GIL only to find Latch._lock is held - Broker drops GIL, sleeps on futex() for _lock - B wakes, acquires GIL, releases _lock - Broker wakes from futex(), acquires lock Now, - B takes lock, updates state, releases lock - B wakes socket by droppping GIL and writing to it - Broker wakes from poll(), acquires GIL and _lock - Everyone lives happily ever after.
1 parent 807cbef commit d6faff0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mitogen/core.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2613,12 +2613,14 @@ def defer(self, func, *args, **kwargs):
26132613
self.stream.transmit_side.fd)
26142614
self._lock.acquire()
26152615
try:
2616-
if not self._deferred:
2617-
self._wake()
2616+
should_wake = not self._deferred
26182617
self._deferred.append((func, args, kwargs))
26192618
finally:
26202619
self._lock.release()
26212620

2621+
if should_wake:
2622+
self._wake()
2623+
26222624

26232625
class IoLoggerProtocol(DelimitedProtocol):
26242626
"""

0 commit comments

Comments
 (0)