Created
January 17, 2010 13:26
-
-
Save hayamiz/279371 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 'thread' | |
$queue = Queue.new | |
workers = Array.new(100).map do | |
Thread.new do | |
block = $queue.pop | |
block.call() | |
end | |
end | |
100.times do | |
$queue.push(lambda { | |
pid = Process.fork do | |
puts :hoge | |
end | |
Process.waitpid(pid) | |
}) | |
end | |
workers.map(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment