txt: ## threadpoolscheduler.md
  class ThreadPoolScheduler
  
  Scheduler that distributes work among a pool of threads
  
  ```raku
  class ThreadPoolScheduler does Scheduler {}
  
  ```
  
  The `ThreadPoolScheduler` has a range of number of threads that it maintains, and it distributes work among those threads. When the upper limit of threads isn't reached yet, and there is work pending, it spawns new threads to handle the work.
  
  # [Methods](#class_ThreadPoolScheduler "go to top of document")[§](#Methods "direct link")
  
  ## [new](#class_ThreadPoolScheduler "go to top of document")[§](#new "direct link")
  
  ```raku
  method new(Int :$initial_threads = 0, Int :$max_threads = 8 * Kernel.cpu-cores)
  
  ```
  
  Creates a new `ThreadPoolScheduler` object with the given range of threads to maintain.
  
  The default value for `:initial_threads` is **0**, so no threads will be started when a `ThreadPoolScheduler` object is created by default.
  
  The default value for `:max_threads` is **64**, unless there appear to be more than 8 CPU cores available. In that case the default will be 8 times the number of CPU cores.
  
  See also the [RAKUDO\_MAX\_THREADS](/programs/03-environment-variables#Other) environment variable to set the default maximum number of threads.
  
  As of release 2022.06 of the Rakudo compiler, it is also possible to specify `Inf` or `*` as a value for `:max_threads`, indicating that the maximum number of threads allowed by the operating system, will be used.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `ThreadPoolScheduler`
  
  
  
  raku-type-graph
  
  
  
  ThreadPoolScheduler
  ThreadPoolScheduler
  
  
  Any
  Any
  
  
  ThreadPoolScheduler->Any
  
  
  
  Scheduler
  Scheduler
  
  
  ThreadPoolScheduler->Scheduler
  
  
  
  Mu
  Mu
  
  
  Any->Mu
  
  [Expand chart above](/assets/typegraphs/ThreadPoolScheduler.svg)
  