Skip to content

Instantly share code, notes, and snippets.

@dustMason
Created May 31, 2013 03:38
Show Gist options
  • Save dustMason/5682810 to your computer and use it in GitHub Desktop.
Save dustMason/5682810 to your computer and use it in GitHub Desktop.
Queue with finite number of threads pattern
@threads = []
@num_of_threads = 8
@queue = Queue.new
# fill queue with items ...
@num_of_threads.times do
@threads << Thread.new {
loop do
break if @queue.length == 0
do_something @queue.deq
end
}
end
@threads.each { |thread| thread.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment