From: Yehuda Katz Date: 2008-12-03T14:10:10+09:00 Subject: [ruby-core:20245] Re: autoload and concurrency ------=_Part_87078_5814908.1228281352070 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Also, this just illustrates that it's possible. In the case of Merb, we aren't doing any hanky panky, and still get the bad behavior from time to time under high concurrency on JRuby. -- Yehuda On Tue, Dec 2, 2008 at 8:58 PM, Charles Oliver Nutter < charles.nutter@sun.com> wrote: > 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 > > -- Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 ------=_Part_87078_5814908.1228281352070 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Also, this just illustrates that it's possible. In the case of Merb, we aren't doing any hanky panky, and still get the bad behavior from time to time under high concurrency on JRuby.

-- Yehuda

On Tue, Dec 2, 2008 at 8:58 PM, Charles Oliver Nutter <charles.nutter@sun.com> wrote:
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




--
Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325
------=_Part_87078_5814908.1228281352070--