Method: Tpool#start

Defined in:
lib/tpool.rb

#startObject

Starts the thread-pool. This is automatically called on initialization.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tpool.rb', line 31

def start
  raise "Already started." if @pool and !@pool.empty?
  
  @pool = Array.new(@args[:threads]) do |i|
    Thread.new do
      begin
        Thread.current[:tpool] = {:i => i}
        
        loop do
          block = @queue.pop
          Thread.current[:tpool][:block] = block
          
          block.run
          Thread.current[:tpool].delete(:block)
        end
      rescue Exception => e
        $stderr.puts e.inspect
        $stderr.puts e.backtrace
      end
    end
  end
end