This class implements a thread pool used for concurrently executing multiple user‐defined functions ("jobs").

Synopsis

Declared in <bdlmt_threadpool.h>

class ThreadPool;

Type Aliases

Name

Job

Member Functions

Name

Description

ThreadPool [constructor]

Constructors

~ThreadPool [destructor]

Call shutdown() and destroy this thread pool.

drain

Disable queuing on this thread pool and wait until all pending jobs complete. Use start to re‐enable queuing.

enabled

Return the state (enabled or not) of the thread pool.

enqueueJob

enqueueJob overloads

maxIdleTime

Return the amount of time (in milliseconds) a thread remains idle before being shut down when there are more than min threads started.

maxIdleTimeInterval

Return the amount of time a thread remains idle before being shut down when there are more than min threads started.

maxThreads

Return the maximum number of threads that are allowed to be running at given time.

minThreads

Return the minimum number of threads that must be started at any given time.

numActiveThreads

Return the number of threads that are currently processing a job.

numPendingJobs

Return the number of jobs that are currently queued, but not yet being processed.

numWaitingThreads

Return the number of threads that are currently waiting for a job.

percentBusy

Return the percentage of wall time spent by each thread of this thread pool executing jobs since the last reset time. The creation of the thread pool is considered a first reset time. This value is calculated as: ` sum(jobExecutionTime) 100% P_busy = ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x ‐‐‐‐‐‐‐‐‐‐ timeSinceLastReset maxThreads ` Note that this percentage reflects the wall time spent per thread, and not CPU time per thread, or not even CPU time per processor. Also note that there is no guarantee that all threads are processed concurrently (e.g., the number of threads could be larger than the number of processors).

resetPercentBusy

Atomically report the percentage of wall time spent by each thread of this thread pool executing jobs since the last reset time, and set the reset time to now. The creation of the thread pool is considered a first reset time. This value is calculated as: ` sum(jobExecutionTime) 100% P_busy = ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x ‐‐‐‐‐‐‐‐‐‐ timeSinceLastReset maxThreads ` Note that this percentage reflects the wall time spent per thread, and not CPU time per thread, or not even CPU time per processor. Also note that there is no guarantee that all threads are processed concurrently (e.g., the number of threads could be larger than the number of processors).

shutdown

Disable queuing on this thread pool, cancel all queued jobs, and shut down all processing threads (after all active jobs complete).

start

Enable queuing on this thread pool and spawn minThreads() processing threads. Return 0 on success, and a non‐zero value otherwise. If minThreads() threads were not successfully started, all threads are stopped.

stop

Disable queuing on this thread pool and wait until all pending jobs complete, then shut down all processing threads.

threadFailures

Return the number of times that thread creation failed.

operator BloombergLP::bslmf::NestedTraitDeclaration<ThreadPool, UsesBslmaAllocator>

Declare that this type uses a bslma allocator.

Friends

Name

Description

BloombergLP::bdlmt::ThreadPoolEntry

Entry point for processing threads.

Created with MrDocs