From: Tomas Matousek Date: 2008-12-03T17:00:00+09:00 Subject: [ruby-core:20253] Re: autoload and concurrency I meant that even if autoload is "fixed" by adding some kind of "in-progress" flag it wouldn't make it thread-safe since "require" itself is still broken as you described. Tomas -----Original Message----- From: Charles.O.Nutter@sun.com [mailto:Charles.O.Nutter@sun.com] On Behalf Of Charles Oliver Nutter Sent: Tuesday, December 02, 2008 10:10 PM To: ruby-core@ruby-lang.org Subject: [ruby-core:20251] Re: autoload and concurrency Require could be made safe if only one thread were allowed to execute requires at a time, globally. Whether that's a reasonable tradeoff, I'm not sure. All things are possible...but many require behavioral changes to Ruby. - Charlie Tomas Matousek wrote: > I think it has already been concluded that autoload and require are > inherently broken in presence of threads. See ruby-core:19860. > > Or am I missing something? > > > > Tomas > > > > *From:* Yehuda Katz [mailto:wycats@gmail.com] > *Sent:* Tuesday, December 02, 2008 9:10 PM > *To:* ruby-core@ruby-lang.org > *Subject:* [ruby-core:20245] Re: autoload and concurrency > > > > 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 > > 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 >