On Dec 22, 2008, at 11:10 AM, Charles Nutter wrote:

> * When the autoload marker is encountered, it is replaced (under  
> lock) with an "autoload in progress" marker. All subsequent threads  
> will then see this marker and wait for the autoloading process to  
> complete. the mechanics of this are a little tricky, but it would  
> guarantee concurrent autoloads would only load the target file once  
> and would always return the intended value to concurrent readers.
> * A single autoload mutex, forcing all autoloads to happen in serial.
>
> There is a potential for deadlock in the first solution,  
> unfortunately, since two threads autoloading two constants with  
> circular autoloaded constant dependencies would ultimately deadlock,  
> each waiting for the other to complete. Because of this, a single  
> autoload mutex for all autoloads may be the only safe solution.

Why not use the same lock that's used by require? The two are clearly  
related, and if there's a require in progress, you'd want to suspend  
autoload until it has finished, and the result of the require might  
affect the behavior of the autoload.


Dave