2008/12/23 Paul Brannan <pbrannan / atdesk.com>: > On Tue, Dec 23, 2008 at 02:14:52AM +0900, Charles Oliver Nutter wrote: >> Paul Brannan wrote: >>> I don't think circular dependencies are a good idea in general, though >>> Ruby shouldn't break if someone tries. >> >> It's not so much that they intend to be circular; more it's that many >> files re-require all resources they expect to need, which over time can >> result in circular dependencies (if every script requires everything it >> things it needs, it's almost assured a few of those will have reverse >> dependencies back). >> >> file_one.rb >> >> require 'file_two' >> require 'file_three' >> require 'file_four' >> >> module Foo .... >> >> file_three.rb >> >> # I know I need file_one to be loaded so module Foo is available... >> require 'file_one' >> >> class Blah; include Foo ... > > I'm still having trouble imagining a case where code like the above is > not a bug. I don't think it is a bug. I found the example a bit difficult because as long as this happens in a single thread there should be no deadlocking issues because of course you would make per file name locks reentrant, i.e. one thread could obtain a single lock multiple times without issues. Maybe this example looks less like a bug in your eyes: t1 = Thread.new do require 'a' require 'b' # do all the work end t2 = Thread.new do require 'b' require 'a' # different order for whatever reasons # do different work end You could even imagine bodies of those threads to be found in separate files which are loaded via "load". Maybe someone wanted to combine two different things in a single script for reasons we do not know. The point is that you get a deadlock if there are per file locks and timing is such that both threads acquire their first lock at the same time and then deadlock on the second one. Kind regards robert -- remember.guy do |as, often| as.you_can - without end