Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preview_mt infinite loop on Windows #13419

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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