Skip to content

Instantly share code, notes, and snippets.

@djfpaagman
Created February 12, 2013 10:03
Show Gist options
  • Save djfpaagman/4761326 to your computer and use it in GitHub Desktop.
Save djfpaagman/4761326 to your computer and use it in GitHub Desktop.
# Encoding: UTF-8
require 'thread'
queue = Queue.new
threads = []
20.times do
threads << Thread.new do
# loop until there are no more things to do
until queue.empty?
# pop with the non-blocking flag set, this raises
# an exception if the queue is empty, in which case
# work_unit will be set to nil
work_unit = queue.pop(true) rescue nil
if work_unit
begin
# ....
rescue Exception => e
puts "-- Found Exception: #{e}"
end
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