class Puma::ThreadPool
def initialize(name, options = {}, &block)
thread.
The block passed is the work that will be performed in each
in the pool.
Maintain a minimum of +min+ and maximum of +max+ threads
def initialize(name, options = {}, &block) @not_empty = ConditionVariable.new @not_full = ConditionVariable.new @mutex = Mutex.new @todo = [] @spawned = 0 @waiting = 0 @name = name @min = Integer(options[:min_threads]) @max = Integer(options[:max_threads]) # Not an 'exposed' option, options[:pool_shutdown_grace_time] is used in CI # to shorten @shutdown_grace_time from SHUTDOWN_GRACE_TIME. Parallel CI # makes stubbing constants difficult. @shutdown_grace_time = Float(options[:pool_shutdown_grace_time] || SHUTDOWN_GRACE_TIME) @block = block @out_of_band = options[:out_of_band] @clean_thread_locals = options[:clean_thread_locals] @reaping_time = options[:reaping_time] @auto_trim_time = options[:auto_trim_time] @shutdown = false @trim_requested = 0 @out_of_band_pending = false @workers = [] @auto_trim = nil @reaper = nil @mutex.synchronize do @min.times do spawn_thread @not_full.wait(@mutex) end end @force_shutdown = false @shutdown_mutex = Mutex.new end