From: Charles Oliver Nutter Date: 2008-12-03T13:58:47+09:00 Subject: [ruby-core:20242] Re: autoload and concurrency Charles Oliver Nutter wrote: > Jim Deville wrote: >> This seems like a strong argument in favor of Ruby-core:20225. > > Fixing autoload to call require doesn't solve anything because there's > still the exact same gap between the time it deletes the special value > and the time when the required file redefines it. A trivial example autoloaded.rb: sleep 1 Bar::Foo = 1 autoloader.rb: module Bar autoload :Foo, 'autoloaded.rb' end t1 = Thread.new { Bar::Foo } t2 = Thread.new { Bar::Foo } t1.join; t2.join Fails every time. Of course "sleep 1" is a longer delay than you'd typically see from requiring in a file, but any delay means there's a change another thread will schedule and see the missing constant before it's defined. Now some of you may be saying "don't do that". But of course, the developer accessing the constant *doesn't know* not to do it, and the developer writing the library containing the autoload just wants to defer a require. Who is breaking the rules? - Charlie