Skip to content

Instantly share code, notes, and snippets.

View justinko's full-sized avatar

Justin Ko justinko

View GitHub Profile
@dustMason
dustMason / threads.rb
Created May 31, 2013 03:38
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