From: Yehuda Katz Date: 2008-12-03T13:23:22+09:00 Subject: [ruby-core:20235] autoload and concurrency ------=_Part_86727_24071107.1228278544100 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Merb uses autoload rather extensively. We have lately observed some disturbing behavior around concurrency. Effectively, because autoload removes the flag before loading the file, if two threads concurrently attempt to access an autoloaded constant, one of the threads can get a NameError. It's easy to reproduce this by adding a sleep to the file being loaded before the constant is defined, and then spinning up two threads that both try to use the constant. This is reproducible in MRI; it does not only happen with JRuby's true parallel execution. The worst part is that no user action can solve this problem: because autoloading is magic, it's impossible for the user to lock the resulting require. In effect, this makes autoloading completely useless for threaded environments. Is this intentional? Is there something we can do at the language level to ameliorate this problem? -- Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 ------=_Part_86727_24071107.1228278544100 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Merb uses autoload rather extensively. We have lately observed some disturbing behavior around concurrency.

Effectively, because autoload removes the flag before loading the file, if two threads concurrently attempt to access an autoloaded constant, one of the threads can get a NameError.

It's easy to reproduce this by adding a sleep to the file being loaded before the constant is defined, and then spinning up two threads that both try to use the constant. This is reproducible in MRI; it does not only happen with JRuby's true parallel execution.

The worst part is that no user action can solve this problem: because autoloading is magic, it's impossible for the user to lock the resulting require. In effect, this makes autoloading completely useless for threaded environments. Is this intentional?

Is there something we can do at the language level to ameliorate this problem?

--
Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325
------=_Part_86727_24071107.1228278544100--