Using class instance variable for mutex in Ruby
问题 Note: The code summary shown below is not a distillation of the code that I had the problem with. I've left this original summary here since someone else already answered, but the actual code is shown in the answer I've provided below. I haven't been able to isolate this to a small failing test case, but I'm getting a failure with the following general construct: class Foo @mutex = Mutex.new .... def self.bar @mutex.synchronize { ... } end end If I create multiple threads invoking Foo.bar ,