I'm probably missing a subtly, but isn;t there a race condition in
lib/singleton?

     module Singleton
       def Singleton.append_features(klass)
         klass.private_class_method(:new)
         klass.instance_eval %{
           @__instance__ = nil
           def instance
             unless @__instance__             # <<<<
               Thread.critical = true
               begin
                 @__instance__ = new
               ensure
                 Thread.critical = false
               end
             end
             return @__instance__
           end
         }
       end

Because the thread is not claimed until after the 'unless', it's
possible for another thread to get in and create an instance, which the
original thread then overwrites.

If that's the case, perhaps the code should be:


           def instance
             unless @__instance__          
               Thread.critical = true
               unless @__instance__          # << add these
                 begin
                   @__instance__ = new
                 ensure
                   Thread.critical = false
                 end
               end                           # <<
             end
             return @__instance__
           end

Also, would it be possible to add (*args) to 'instance' and the call
to 'new'?

If these are correct changes, I'd be happy to submit a patch.

Regards


Dave



-- 
Thomas Consulting.
Innovative and successful developments with Unix, Java, C, and C++. 

Now in bookstores:
 The Pragmatic Programmer.  www.pragmaticprogrammer.com/ppbook/