Skip to content

Instantly share code, notes, and snippets.

@manveru
Forked from jcoene/gist:5034155
Last active December 18, 2015 03:19
Show Gist options
  • Save manveru/5717145 to your computer and use it in GitHub Desktop.
Save manveru/5717145 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
threads = 100.times.map do |n|
Thread.new n do |m|
base = 1 + (m * 100)
100.times.map do |i|
base + i
end
end
end
result = threads.reduce(0) do |sum, thread|
sum + thread.join.value.reduce(:+)
end
puts "The multi-threaded result is: #{result}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment