Created
March 31, 2010 16:47
-
-
Save hayeah/350560 to your computer and use it in GitHub Desktop.
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 characters
| require 'thread' | |
| queue = Queue.new | |
| workers = 10.times.map do |i| | |
| ts = Thread.new do | |
| loop { | |
| queue.pop.call | |
| Thread.pass | |
| } | |
| end | |
| end | |
| loop { | |
| # p [:size,queue.size] | |
| Thread.pass unless queue.empty? | |
| 100.times do | |
| queue << lambda { | |
| # define work here | |
| "work" | |
| } | |
| end | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment