-
-
Save lune-sta/2aa41d8f2fb0f300a71c 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
PROCESSORS = (ARGV[0] || 1).to_i | |
pids = [] | |
workers = PROCESSORS.times.map do |i| | |
uri = "druby://localhost:#{12345 + i}" | |
pids << fork { DRb.start_service(uri, MonteCarlo.new(i)); sleep } | |
DRbObject.new_with_uri(uri) | |
end | |
begin | |
q = Queue.new | |
sleep 0.1 | |
ts = workers.map do |foo| | |
Thread.start(foo) {|f| q.push(f.dice(n))} | |
end | |
ts.each{|t| t.join} | |
p q.size.times.map{q.pop}.min | |
ensure | |
pids.each {|pid| Process.kill(:TERM, pid)} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment