Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created December 11, 2015 19:42
Show Gist options
  • Select an option

  • Save dpaluy/ff68ee2b82919087e232 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/ff68ee2b82919087e232 to your computer and use it in GitHub Desktop.
Multi-threaded Queue in Ruby
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