Skip to content

Instantly share code, notes, and snippets.

@laser
Created January 22, 2014 21:33
Show Gist options
  • Save laser/8567763 to your computer and use it in GitHub Desktop.
Save laser/8567763 to your computer and use it in GitHub Desktop.
Multithread unsafe
def add_range_unsafe
c = StatefulCalculator.new
threads = (1..256).each_slice(16).map do |range|
Thread.new do
range.each { |n| c.add n }
end
end
threads.map(&:join)
c.result
end
puts add_range_unsafe # 24399
puts add_range_unsafe # 26126
puts add_range_unsafe # 25674
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment