From: "Iñaki Baz Castillo" Date: 2012-06-11T00:33:25+09:00 Subject: Re: Is "a,b=c,d" atomic? or do I need a Mutex? 2012/6/10 Iñaki Baz Castillo : > Hi, I have two methods that could be called by different threads and > both use the same array: > >  def method1 object >    MyModule.array << object >  end > >  def method2 >    array, MyModule.array = MyModule.array, nil >  end > > Do I need a Mutex (#synchronize() method) here? I think the answer is > NOT since both actions in the array are "atomic". Am I right? Auto-reply: Yes, it's atomic: def test a,b ; $a, $b = a, b ; end times = 10000000 t1 = Thread.new { 1.upto(times) do |i| test(i,i) end } t2 = Thread.new { 1.upto(times) { raise "NOT EQUAL" if $a!=$b } } t1.join t2.join puts "OK" => "OK" -- Iñaki Baz Castillo