Created
December 11, 2015 19:42
-
-
Save dpaluy/ff68ee2b82919087e232 to your computer and use it in GitHub Desktop.
Multi-threaded Queue in Ruby
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
| num_workers = 20 | |
| queue = SizedQueue.new num_workers * 2 | |
| threads = num_workers.times.map do | |
| Thread.new do | |
| while item = queue.pop | |
| #do_something item | |
| end | |
| end | |
| end | |
| list.each {|item| queue << item} | |
| queue.close | |
| threads.each(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment