Skip to content

Commit

Permalink
Fix preview_mt infinite loop on Windows (#13419)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed May 3, 2023
1 parent 3226a35 commit 2e43fc4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/crystal/scheduler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Crystal::Scheduler
{% end %}

{% if flag?(:preview_mt) %}
@fiber_channel = Crystal::FiberChannel.new
private getter(fiber_channel : Crystal::FiberChannel) { Crystal::FiberChannel.new }
@free_stacks = Deque(Void*).new
{% end %}
@lock = Crystal::SpinLock.new
Expand Down Expand Up @@ -199,6 +199,7 @@ class Crystal::Scheduler
end

def run_loop
fiber_channel = self.fiber_channel
loop do
@lock.lock
if runnable = @runnables.shift?
Expand All @@ -208,7 +209,7 @@ class Crystal::Scheduler
else
@sleeping = true
@lock.unlock
fiber = @fiber_channel.receive
fiber = fiber_channel.receive

@lock.lock
@sleeping = false
Expand All @@ -222,7 +223,7 @@ class Crystal::Scheduler
def send_fiber(fiber : Fiber)
@lock.lock
if @sleeping
@fiber_channel.send(fiber)
fiber_channel.send(fiber)
else
@runnables << fiber
end
Expand Down

0 comments on commit 2e43fc4

Please sign in to comment.