class ChefUtils::DefaultThreadPool
The DefaultThreadPool
has a fixed thread size and has no queue of work and the behavior on failure to find a thread is for the caller to run the work. This contract means that the thread pool can be called recursively without deadlocking and while keeping the fixed number of threads (and not exponentially growing the thread pool with the depth of recursion).
Constants
- DEFAULT_THREAD_SIZE
Attributes
Size of the thread pool, must be set before getting the thread pool or calling parallel_map/parallel_each. Does not (but could be modified to) support dynamic resizing. To get fully synchronous behavior set this equal to zero rather than one since the caller will get work if the threads are busy.
@return [Integer] number of threads
Public Instance Methods
Memoizing accessor for the thread pool
@return [Concurrent::ThreadPoolExecutor] the thread pool
# File lib/chef-utils/parallel_map.rb, line 118 def pool @pool ||= Concurrent::ThreadPoolExecutor.new( min_threads: threads || DEFAULT_THREAD_SIZE, max_threads: threads || DEFAULT_THREAD_SIZE, max_queue: 0, # "synchronous" redefines the 0 in max_queue to mean 'no queue' instead of 'infinite queue' # it does not mean synchronous execution (no threads) but synchronous offload to the threads. synchronous: true, # this prevents deadlocks on recursive parallel usage fallback_policy: :caller_runs ) end