Created
June 14, 2013 16:19
-
-
Save headius/5783237 to your computer and use it in GitHub Desktop.
Example of nondeterministic insertion order in MRI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xt-jruby-local ~/projects/jruby $ cat blah.rb | |
expected = (0...100000).to_a * 50 | |
array = [] | |
50.times.map do | |
Thread.new do | |
100000.times do |i| | |
array << i | |
end | |
end | |
end.each(&:join) | |
diffs = [] | |
5000000.times {|i| | |
diffs << i if expected[i] != array[i] | |
} | |
puts "total diffs: #{diffs.size}" | |
puts "first diff: #{diffs[0]} expected #{expected[diffs[0]]} but was #{array[diffs[0]]}" | |
ext-jruby-local ~/projects/jruby $ ruby2.0.0 blah.rb | |
total diffs: 400000 | |
first diff: 232 expected 232 but was 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment