Nobuyoshi Nakada wrote:
> It's same as two threads requiring without autoloading.

I'm not sure this is safe enough. If the first thread has already set 
the constant, the second thread would not know it is an autoload and 
would return its value immediately. The resource the constant points at 
may not be done loading.

my_file.rb:

module XXX
   class Foo
     # HERE
     def bar; ... end
   end
end

my_autoload.rb:

module XXX
   autoload :Foo, "my_file.rb"
end

# Thread 1
Thread.new { XXX::Foo.new.bar }

# Thread 2
Thread.new { XXX::Foo.new.bar }

Thread 1 tries to look up XXX::Foo and starts requiring my_file.rb. It 
reaches # HERE above and the XXX::Foo constant now points at the Foo 
class. Now thread 2 looks up XXX::Foo, and since it is not an autoload 
marker it gets the incomplete Foo class. Thread 2 blows up when it tries 
to call bar because bar is not yet defined.