Skip to content

Instantly share code, notes, and snippets.

@ik5
Last active October 10, 2021 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ik5/3e7184174cf0bad231b931aaab131eba to your computer and use it in GitHub Desktop.
Save ik5/3e7184174cf0bad231b931aaab131eba to your computer and use it in GitHub Desktop.
example on how to do threadpool in ruby
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.map(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment