Dave Thomas wrote:
> 
> 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.

autoload is a little trickier than that since it needs some intermediate 
state that isn't totally undefined but doesn't show up as 
yet-to-be-autoloaded either. But yeah, if we're willing to expect that 
require and autoload are one-thread-at-a-time, a lot of problems go away.

I'd say load could potentially be unsynchronized, since it's more 
explicit and doesn't make any guarantees about whether it will fire 
twice, etc. But perhaps it should just be done across the board.

- Charlie