bruno- / fiber_scheduler

Ruby's missing Fiber Scheduler implementation.
MIT License
120 stars 3 forks source link

Too many inner loops causes a crash #3

Open fallwith opened 2 years ago

fallwith commented 2 years ago

Hi there. Thank you for all of your efforts with fiber_scheduler and the thought and planning that you've put into positioning it as a great default. I'm getting up to speed with Ruby 3 non-blocking fibers and have benefitted from your related writing.

I was playing around with using the fiber_scheduler gem and comparing it to other schedulers. I am using a non-block context (Fiber.set_scheduler). In an effort to have some test code do something that would take a little longer to complete, I added a 1_000.times loop wrapper and found that doing so causes a crash.

Code to reproduce:

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'fiber_scheduler'

Thread.new do
  Fiber.set_scheduler FiberScheduler.new
  %w[apple banana grape lemon cherry lime].each do |fruit|
    Fiber.schedule do
      start_time = Time.now
      1_000.times do
        Math.exp(fruit.chars.sort.reverse.uniq.map(&:upcase).shuffle.sample.ord)
      end
      stop_time = Time.now
      puts "==> Elapsed #{stop_time - start_time} <== "
    end
  end
end.join

Error output:

~/.rubies/ruby-3.2.0-preview1/lib/ruby/gems/3.2.0+1/gems/fiber_scheduler-0.13.0/lib/fiber_scheduler.rb:122:in `select': undefined method `alive?' for [:blocking, #<RubyVM::AbstractSyntaxTree::Node:FALSE@47:21-47:26>]:Array (NoMethodError)
bruno- commented 2 years ago

Hi,

I can reproduce this problem. I'll take a look!