Skip to content

Commit 21aba17

Browse files
committed
Fix: MT may fail to wake other schedulers after evloop run
1 parent d5bb3bc commit 21aba17

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/fiber/execution_context/multi_threaded/scheduler.cr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ module Fiber::ExecutionContext
142142
yield @global_queue.grab?(@runnables, divisor: @execution_context.size)
143143

144144
if @execution_context.lock_evloop? { @event_loop.run(pointerof(list), blocking: false) }
145-
if fiber = enqueue_many(pointerof(list))
145+
unless list.empty?
146+
# must stop spinning before calling enqueue_many that may call
147+
# wake_scheduler which returns immediately if a thread is
148+
# spinning... but we're spinning, so that would always fail to
149+
# wake sleeping schedulers despite having runnable fibers
146150
spin_stop
147-
yield fiber
151+
yield enqueue_many(pointerof(list))
148152
end
149153
end
150154

0 commit comments

Comments
 (0)