On Dec 3, 2008, at 8:40 PM, hemant wrote: > Why not use const_missing for lazy loading and protect "require" by a > mutex (there could be a deadlock, if requires are nested, but in > practice I was assuming it can be avoided) I don't see how there could be a deadlock: once you've claimed the mutex, your thread is the one that will do requires. Any requires nested inside the original one will be executed in the same thread, so simply rescue and ignore the recursive lock exception. Honestly, folks, I really don't see what all the fuss is about. One mutex, claimed by autoload, require, and load, will do the trick. If autoload claims it, then it gets to do the requires if it needs to, because they'll operate in-thread. If require claims it, then only requires and autoloads in that same thread will run until the original require finishes. Etc etc... No deadlock, and no contention. The current MRI implementation has a bug. Fix it with a mutex, and it all gets better. Then we find the next global thing that's not thread safe... :) Dave