Skip to content

Instantly share code, notes, and snippets.

@keroxp
Created June 27, 2012 12:23
Show Gist options
  • Save keroxp/3003718 to your computer and use it in GitHub Desktop.
Save keroxp/3003718 to your computer and use it in GitHub Desktop.
素数かつフィボナッチ数を出力するプログラム
require "rubygems"
require "Monitor"
require "./fib.rb"
require "./prime.rb"
l = Monitor.new
h = {}
threadF = Thread.new do
Fib.calc { |f|
if h[f] == "p" then
puts f
end
l.synchronize do
h[f] = "f"
end
}
end
threadP = Thread.new do
Prime.calc { |p|
if h[p] == "f" then
puts p
end
l.synchronize do
h[p] = "p"
end
}
end
threadF.join
threadP.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment