diff --git a/scheduler.c b/scheduler.c index 8ec5039096..f0bb5ee597 100644 --- a/scheduler.c +++ b/scheduler.c @@ -39,7 +39,9 @@ Init_Scheduler(void) VALUE rb_scheduler_close(VALUE scheduler) { - return rb_funcall(scheduler, id_close, 0); + if (rb_respond_to(scheduler, id_close)) { + return rb_funcall(scheduler, id_close, 0); + } } VALUE diff --git a/test/fiber/test_scheduler.rb b/test/fiber/test_scheduler.rb index 23b59c06b0..d85aa7a6ce 100644 --- a/test/fiber/test_scheduler.rb +++ b/test/fiber/test_scheduler.rb @@ -49,4 +49,12 @@ class TestFiberScheduler < Test::Unit::TestCase end RUBY end + + def test_optional_close + thread = Thread.new do + Thread.current.scheduler = Object.new + end + + thread.join + end end