From: Charles Oliver Nutter Date: 2011-11-29T19:55:25+09:00 Subject: [ruby-core:41389] Re: [Backport93 - Backport #5621] Please backport thread-safe autoloading patch On Tue, Nov 29, 2011 at 4:43 AM, Charles Oliver Nutter wrote: > I think an additional warning about doing requires lazily might be > useful...perhaps any require that happens on some non-main thread that > *isn't* in response to a require should elicit a warning? Or perhaps > when we detect concurrent non-autooad requires (i.e. two threads doing > separate requires at the same time, regardless of the files they're > loading) we should warn? Here's an impl of the latter. The first thread to start requiring acquires a lock, and subsequent threads that attempt to require simply warn. It's primitive, since it warns on those other threads for *every* require including the topmost, but it demonstrates the idea. https://gist.github.com/1404402 Example uses: system ~/projects/jruby $ jruby -e "Thread.new { require 'fileutils' }; require 'optparse'" :1 warning: concurrent require of `fileutils` detected /Users/headius/projects/jruby/lib/ruby/1.8/fileutils.rb:979 warning: concurrent require of `etc` detected system ~/projects/jruby $ jruby -e "Thread.new { require 'fileutils' }; Thread.new { require 'optparse' }" :1 warning: concurrent require of `optparse` detected system ~/projects/jruby $ jruby -e "Thread.new { require 'fileutils' }.join; require 'optparse'" system ~/projects/jruby $