From: Walton Hoops Date: 2010-03-14T01:17:13+09:00 Subject: Re: Is ruby-1.9 threads data safer? On 3/13/2010 7:09 AM, Benoit Daloze wrote: > On 12 March 2010 18:03, Roger Pack wrote: > > >> >>> My ruby version is 1.9, running under Linux-2.6.31 kernel. >>> For the code above, though we know the @count isn't safe for sharing. >>> But the result is always correct. >>> So can we say ruby-1.9 behaves better on threads than 1.8? >>> >> Nope you just got lucky :) >> -r >> -- >> Posted via http://www.ruby-forum.com/. >> >> >> > We've got a big luck in 1.9 then ;) > > All my tries in 1.8 failed and in 1.9.2 passed > > My suspicion is it has to do with the way threads work in 1.9. Read http://blog.urbylog.info/2010/01/inside-ruby-19-interpreter-threading-in.html. I suspect that the GVL is not released while executing the += operator, making a real context switch impossible, therefore preventing the other thread from even running while the assignment is taking place. Of course you should NOT be counting on the GVL to synchronize your code.