lib/thread_pool.rb
# def dispatch actually manages our threads so the pool remains max size and no larger. In reality, the pool does get bigger, but it the only active thread will be max_size
def dispatch actually manages our threads so the pool remains max size and no larger. In reality, the pool does get bigger, but it the only active thread will be max_size
def dispatch actually manages our threads so the pool remains max size and no larger . In reality the pool does get bigger but it the only active thread will be max_size
def dispatch(*args)
    Thread.new(sleep(1)) do
      @pool_mutex.synchronize do
        $LOG.debug("Pool is presently #{@pool.size}")
        while @pool.size >= @max_size
          print "Pool is full; waiting to run #{args.join(',')}...\n" if $DEBUG
          @pool_cv.wait(@pool_mutex)
        end
      end
      @pool << Thread.current
      begin
          yield(*args)
      rescue StandardError => e
        exception(self, e, *args)
      ensure
        @pool_mutex.synchronize do
          @pool.delete(Thread.current)
          @pool_cv.signal
        end
        end
    end
  end
def dispatch ( * args ) Thread . new ( sleep ( 1 ) ) do @pool_mutex . synchronize do $LOG . debug ( "Pool is presently #{@pool.size}" ) while @pool . size >= @max_size print "Pool is full; waiting to run #{args.join(',')}...\n" if $DEBUG @pool_cv . wait ( @pool_mutex ) end end @pool << Thread . current begin yield ( * args ) rescue StandardError => e exception ( self , e , * args ) ensure @pool_mutex . synchronize do @pool . delete ( Thread . current ) @pool_cv . signal end end end end
def dispatch actually manages our threads so the pool remains max size and no larger.
def dispatch actually manages our threads so the pool remains max size and no larger .
# Wait for space in the pool. # Sleep until some other thread calls @pool_cv.signal. # Remove the thread from the pool. # Signal the next waiting thread that there's a space in the pool.
args
<not_specific>