diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2022-05-08 10:22:58 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 10:22:58 +1200 |
commit | fd6cef79f54bebab1a49256034687dcc01a09eab (patch) | |
tree | 75b35bc5a2260033dcac1bec60822ff0dafda570 /test/fiber/test_scheduler.rb | |
parent | 679b6e43c758bc8a509fc764638e2c30fb7f4279 (diff) | |
download | ruby-fd6cef79f54bebab1a49256034687dcc01a09eab.tar.gz |
Use a proper mutex for autoloading features. (#5788)
Object#autoload implements a custom per-thread "mutex" for blocking
threads waiting on autoloading a feature. This causes problems when used
with the fiber scheduler. We swap the implementation to use a Ruby mutex
which is fiber aware.
Diffstat (limited to 'test/fiber/test_scheduler.rb')
-rw-r--r-- | test/fiber/test_scheduler.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/fiber/test_scheduler.rb b/test/fiber/test_scheduler.rb index 1870ab1c33..08ac386c29 100644 --- a/test/fiber/test_scheduler.rb +++ b/test/fiber/test_scheduler.rb @@ -104,4 +104,23 @@ class TestFiberScheduler < Test::Unit::TestCase thread.join end + + def test_autoload + Object.autoload(:TestFiberSchedulerAutoload, File.expand_path("autoload.rb", __dir__)) + + thread = Thread.new do + scheduler = Scheduler.new + Fiber.set_scheduler scheduler + + 10.times do + Fiber.schedule do + Object.const_get(:TestFiberSchedulerAutoload) + end + end + end + + thread.join + ensure + Object.send(:remove_const, :TestFiberSchedulerAutoload) + end end |