Skip to content

Instantly share code, notes, and snippets.

@crimsonwoods
Created April 19, 2014 05:53
Show Gist options
  • Save crimsonwoods/11075375 to your computer and use it in GitHub Desktop.
Save crimsonwoods/11075375 to your computer and use it in GitHub Desktop.
perform fib39 concurrently
# 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