class Puma::ThreadPool

def shutdown(timeout=-1)


threads. Finally, wait 1 second for remaining threads to exit.
Next, wait an extra +@shutdown_grace_time+ seconds then force-kill remaining
Wait +timeout+ seconds then raise +ForceShutdown+ in remaining threads.
Tell all threads in the pool to exit and wait for them to finish.
def shutdown(timeout=-1)
  threads = with_mutex do
    @shutdown = true
    @trim_requested = @spawned
    @not_empty.broadcast
    @not_full.broadcast
    @auto_trim&.stop
    @reaper&.stop
    # dup workers so that we join them all safely
    @workers.dup
  end
  if timeout == -1
    # Wait for threads to finish without force shutdown.
    threads.each(&:join)
  else
    join = ->(inner_timeout) do
      start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
      threads.reject! do |t|
        elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
        t.join inner_timeout - elapsed
      end
    end
    # Wait +timeout+ seconds for threads to finish.
    join.call(timeout)
    # If threads are still running, raise ForceShutdown and wait to finish.
    @shutdown_mutex.synchronize do
      @force_shutdown = true
      threads.each do |t|
        t.raise ForceShutdown if t[:with_force_shutdown]
      end
    end
    join.call(@shutdown_grace_time)
    # If threads are _still_ running, forcefully kill them and wait to finish.
    threads.each(&:kill)
    join.call(1)
  end
  @spawned = 0
  @workers = []
end