Skip to content

Instantly share code, notes, and snippets.

@headius
Created June 14, 2013 16:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/5783237 to your computer and use it in GitHub Desktop.
Save headius/5783237 to your computer and use it in GitHub Desktop.
Example of nondeterministic insertion order in MRI
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