Introduce global lock to avoid concurrent require
Current implementation of "require" has locks for each file (expanded name from required feature) and serializes file loading from Threads. The first Thread acquires the lock for the file and starts loading. The second Thread waits for acquiring the lock, and when the first Thread release the lock, it acquires the lock, then returns immediately.
This can cause deadlock by cross-require from Threads.
And code that does not properly use "require" could meet several problems;
- constants can be defined before they're ready for use
- classes can be modified while they're being used
- global state can be initialized at the same time it's in use
Proposal: introduce global (per VM) lock to avoid concurrent file loading by "require" so that only one Thread can call "require" at the same time.
I don't have pros/cons list at this moment. Let's discuss it, too.
Derived from a discussion at #5621 (thread-safe autoload)