class RbbtThreadQueue
Attributes
Public Class Methods
Source
# File lib/rbbt/util/concurrency/threads.rb, line 69 def self.each(list, num = 3, &block) q = RbbtThreadQueue.new num q.init(&block) list.each do |elem| q.process elem end q.join end
Source
# File lib/rbbt/util/concurrency/threads.rb, line 37 def initialize(num_threads) @num_threads = num_threads @threads = [] @queue = Queue.new @mutex = Mutex.new end
Public Instance Methods
Source
# File lib/rbbt/util/concurrency/threads.rb, line 61 def clean threads.each{ |t| t.clean }.clear end
Source
# File lib/rbbt/util/concurrency/threads.rb, line 44 def init(use_mutex = false, &block) clean num_threads.times do |i| @threads << RbbtThreadQueueWorker.new(queue, use_mutex ? mutex : nil, &block) end end
Source
# File lib/rbbt/util/concurrency/threads.rb, line 51 def join while queue.length > 0 or queue.num_waiting < @threads.length Thread.pass raise "No worker thread survived" if @threads.empty? and queue.length > 0 end @threads.delete_if{|t| t.alive?} @threads.each{|t| t.raise Aborted } @threads.each{|t| t.join(0.1) } end
Source
# File lib/rbbt/util/concurrency/threads.rb, line 65 def process(e) queue << e end