On Tue, Mar 11, 2003 at 07:16:34AM +0900, Hal E. Fulton wrote: > This discussion has made me wonder if there is > some "generic" way of handling serializing in > druby. > > Wouldn't it be nice if you could simply mix in > a module, like > > myobj.extend(ThreadSafe) > > and then start the service normally and forget it? > > How would you approach this? I have an idea but > it seems clunky. Hmm. DRb uses obj.__send__ to invoke a method. (I don't know what the difference is between this and obj.send) So, in principle you could do: module ThreadSafe def __tsinit @__tsmutex = Mutex.new end def __send__(*args) @__tsmutex.synchronize { super(*args) } end end When you run this Ruby says: threadsafe.rb:5: warning: redefining `__send__' may cause serious problem but surprisingly it does actually seem to work: a = SlowServer.new a.extend ThreadSafe a.__tsinit DRb.start_service('druby://localhost:9000', a) I would really like the 'extend ThreadSafe' to perform the initialisation of the instance variable automatically though. Is there a way to do that? Regards, Brian.