From: Caleb Clausen Date: 2007-06-11T05:13:22+09:00 Subject: Re: Synchronized attr_accessor Nasir Khan wrote: > define_method(meth) do |*args| > @__ms_lock = Mutex.new unless @__ms_lock > @__ms_lock.synchronize do > self.send("__nonsync_#{meth}",*args) > end > end This still isn't completely thread-safe, I'm afraid. If the lock doesn't exist yet and two threads both call some synchronized method on the same object, you've got a race condition. I'd suggest creating the lock upfront, before the synchronization wrappers are defined.... unfortunately, that makes implementing this idea a bit more complicated.