0
# in initialize
@queue = Queue.new
@threads = Array.new(NUM_THREADS) do
Thread.new do
until @queue.empty?
puts @queue.shift
end
end
end
# later in another method, calling
@threads.each { |t| puts t.alive? } # puts false
@queue.push('something else')
# new item is not processed by thread
如何保持一個Ruby線程活着,因此能保持接受來自隊列的東西?