2008/12/22 Dave Thomas <dave / pragprog.com>:
>
> On Dec 22, 2008, at 10:50 AM, Charles Nutter wrote:
>
>> * Modify all require implementations to immediately return false if the
>> requested resource has already been loaded or is in the process of being
>> loaded. This does not guarantee the file has *completed* loading, but wo=
uld
>> ensure we do not double-initialize anything in a required file. Along wi=
th
>> this, we would simply advise all developers to avoid concurrent requires
>> * Modify all require implementations to use a global lock, disallowing
>> concurrent requires entirely. This means required files must be
>> well-behaved; they can't start up new threads that do requires or perfor=
m
>> long-running tasks. It would fix the concurrency problem entirely and
>> requires from multiple threads would simply happen in serial.
>>
>> Both of these require behavioral changes in at least some Ruby versions,
>> with the latter requiring the most drastic changes (since concurrent
>> requires will no longer run in parallel, as they do now, even if no comm=
on
>> resources are in contention).
>>
>> A third option, having a per-resource lock, is infeasible due to the
>> strong possibility of deadlocks. If two threads require separate files w=
ith
>> circular dependencies, deadlock is almost assured. If this mechanism has
>> been implemented in any versions of Ruby, it should be replaced with eit=
her
>> of the two solutions above.
>
> The first solution will not be thread safe, for the reasons stated=97the =
fact
> that require returns does not mean that the file is actually loaded. This
> would lead to hard-to-diagnose problems.

Absolutely, I think this is not really a solution.

> I think the global lock is the way to go. And I find it hard to come up w=
ith
> any code this could currently break.

Please see my reply (link below) where I constructed a deadlock.
Granted, you need to be able to create threads when holding the
require lock - so if that is forbidden all is well.  But the lock
alone is not enough.

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/20802

Cheers

robert


--=20
remember.guy do |as, often| as.you_can - without end