From: Josh Cheek Date: 2011-10-19T22:26:12+09:00 Subject: Re: Ruby and threading --00221597573675679b04afa6c8a4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, Oct 19, 2011 at 7:56 AM, Sandor Sz=FCcs wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA512 > > On 10/19/11 9:11 AM, Josh Cheek wrote: > > > ruby-1.9.3-rc1 0.064 seconds 400000 elements in array (should be > > 400000) > > > > rbx-2.0.0pre 0.232 seconds 398877 elements in array (should be > > 400000) > > > > jruby-1.6.4 0.069 seconds 398709 elements in array (should be > > 400000) > > > > macruby-0.10 0.076 seconds 366231 elements in array (should be > > 400000) > > > > > > $ cat needs_gil.rb puts '', ENV['RUBY_VERSION'] > > > > @array, threads =3D [], [] start =3D Time.now 4.times do threads << > > Thread.new { (1..100_000).each {|n| @array << n} } end > > threads.each{|t| t.join } stop =3D Time.now > > > > puts "%0.3f seconds" % (stop - start), @array.size > > I think it's pretty obvious, that implementations without GIL should > behave exactly as you have shown. > You did not use synchronization to append an item to your shared > object, so sometimes items will get lost. > - -- > That's the point, to show why the GIL is useful. --00221597573675679b04afa6c8a4--