Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Last active December 19, 2015 10:29
Show Gist options
  • Save ryandotsmith/5940245 to your computer and use it in GitHub Desktop.
Save ryandotsmith/5940245 to your computer and use it in GitHub Desktop.
# A program that works jobs in newly created UNIX
# process by calling fork. The number of processes
# running at any given time is bounded by our use
# of a sized queue.
require 'thread'
@limiter = SizedQueue.new(4)
def work(i)
1 * i
end
10_000.times do |i|
@limiter.enq(1)
Thread.new do
Process.wait fork {work(i)}
@limiter.deq
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment