You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
~/w/autoload-thread-safety> ruby --version
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.2.0]
~/w/autoload-thread-safety> ruby -I. test.rb
A accessing const
defining Foo::Bar
B sees Foo::Bar not defined yet
done defining Foo::Bar
A finished with const
on JRuby 1.7.11:
~/w/autoload-thread-safety> jruby --2.0 --version
jruby 1.7.11 (2.0.0p195) 2014-02-24 86339bb on Java HotSpot(TM) 64-Bit Server VM 1.6.0_51-b11-457-11M4509 [darwin-x86_64]
~/w/autoload-thread-safety> jruby --2.0 -I. test.rb
A accessing const
defining Foo::Bar
done defining Foo::Bar
A finished with const
B accessing const
B finished with const
PS: please note that I think JRuby's behavior makes more sense and should have been the correct one 😃.
The text was updated successfully, but these errors were encountered:
Not sure why I didn't comment here before 9.3 but this appears to match Ruby 2.6.8 behavior now:
$ jruby -I. test.rb
A accessing const
defining Foo::Bar
B accessing const
done defining Foo::Bar
B finished with constA finished with const
$ rvm ruby-2.6.8 do ruby -I. test.rb
A accessing const
defining Foo::Bar
B accessing const
done defining Foo::Bar
A finished with const
B finished with const
Note that A and B finished at the same time, which may change the order, but this is expected for parallel execution. I think we can call this fixed in 9.3.
From the discussion on rails/rails#17091.
On MRI if other thread (Thread A) is
autoload
ing aFoo
constant,defined?(Foo)
(in Thread B) returns right away returningfalse
.On JRuby
defined?(Foo)
(in Thread B) blocks and waits for Thread A to finish.Script to repro: https://gist.github.com/thedarkone/d1c26e08f7eca3bc224e
MRI:
on JRuby 1.7.11:
PS: please note that I think JRuby's behavior makes more sense and should have been the correct one 😃.
The text was updated successfully, but these errors were encountered: