-
-
Save maasha/2a721b8deb98c7f4030e 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 'pp' | |
def fib(n) n < 2 ? n : fib(n-1)+fib(n-2); end # Lousy Fibonacci calculator <- heavy job | |
input = (0 .. 10).to_enum | |
enums = [input] | |
threads = [] | |
mutex = Mutex.new | |
10.times do |i| | |
thread = Thread.new(enums[i]) do |input| | |
Enumerator.new do |yielder| | |
input.each { |e| yielder << (e + 1); fib(30) } | |
end.lazy | |
end | |
thread.join | |
enums[i + 1] = thread.value | |
end | |
pp enums | |
enums.last.each { |e| p e } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment