Last active
December 19, 2015 10:29
Revisions
-
♠ ace hacker revised this gist
Jul 6, 2013 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -17,9 +17,10 @@ def work(i) # If the limiter is full, then we will block until space permits. @limiter.enq(1) Thread.new do begin Process.wait fork {work(i)} # Once we are done with our work and our process has exited, # we can allow another process to run. ensure @limiter.deq end end end -
♠ ace hacker revised this gist
Jul 6, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ # Run at most 4 UNIX processes for any given time. @limiter = SizedQueue.new(4) # Trivial. Could be anything. def work(i) 1 * i end -
♠ ace hacker revised this gist
Jul 6, 2013 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,16 +5,20 @@ require 'thread' # Run at most 4 UNIX processes for any given time. @limiter = SizedQueue.new(4) def work(i) 1 * i end 10_000.times do |i| # If the limiter is full, then we will block until space permits. @limiter.enq(1) Thread.new do Process.wait fork {work(i)} # Once we are done with our work and our process has exited, # we can allow another process to run. @limiter.deq end end -
♠ ace hacker created this gist
Jul 6, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ # 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