-
-
Save cabb/432f0c24170fc179af9b01ab7a6eea55 to your computer and use it in GitHub Desktop.
example on how to do threadpool in ruby
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 | |
threads = [] | |
1.step(1000) do |i| | |
queue << i | |
end | |
8.times do | |
threads << Thread.new do | |
until queue.empty? | |
work_unit = queue.pop(true) rescue nil | |
if work_unit | |
puts work_unit | |
sleep 5 | |
end | |
end | |
end | |
end | |
threads.each { |t| t.join } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment