-
-
Save yorickpeterse/c882dc0293ae55ebd346 to your computer and use it in GitHub Desktop.
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
require 'thread' | |
input = [10, 12, 14, 18] | |
output = [] | |
threads = [] | |
lock = Mutex.new | |
def fib(n) | |
return n < 2 ? n : fib(n-1) + fib(n-2) | |
end | |
10.times do |index| | |
threads << Thread.new do | |
input.each do |some_value| | |
lock.synchronize { output << fib(some_value) } | |
end | |
end | |
end | |
threads.each(&:join) | |
p output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment