Created
April 19, 2014 05:53
-
-
Save crimsonwoods/11075375 to your computer and use it in GitHub Desktop.
perform fib39 concurrently
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
# Fib 39 | |
def fib n | |
return n if n < 2 | |
fib(n-2) + fib(n-1) | |
end | |
t1 = Thread.new do | |
fib(39) | |
end | |
t2 = Thread.new do | |
fib(39) | |
end | |
t3 = Thread.new do | |
fib(39) | |
end | |
r1 = t1.join | |
r2 = t2.join | |
r3 = t3.join | |
puts "fib(39) = #{r1}, #{r2}, #{r3}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment