2.8 KiB
Thread Pools
A thread pool (Wikipedia) accepts and executes lightweight work items called "tasks", using a carefully managed group of dedicated long-running worker threads. The worker threads perform the work items in parallel without forcing each work item to assume the burden of starting and destroying a dedicated thead.
Classes
ThreadPoolInterface
The ThreadPoolInterface abstract interface is an extension of the
OutOfLineExecutor (see the executors architecture guide) abstract interface, adding
startup, shutdown, and join virtual member functions. It is the base class for our thread pool
classes.
ThreadPool
ThreadPool is the most basic concrete thread pool. The number of worker threads
is adaptive, but configurable with a min/max range. Idle worker threads are reaped (down to the
configured min), while new worker threads can be created when needed (up to the configured max).
ThreadPoolTaskExecutor
ThreadPoolTaskExecutor is not a thread pool, but rather a
TaskExecutor that uses a ThreadPoolInterface and a NetworkInterface to execute scheduled
tasks. It's configured with a ThreadPoolInterface over which it takes ownership, and a
NetworkInterface, of which it shares ownership. With these resources it implements the elaborate
TaskExecutor interface (see executors).
NetworkInterfaceThreadPool
NetworkInterfaceThreadPool is a thread pool implementation that
doesn't actually own any worker threads. It runs its tasks on the background thread of a
NetworkInterface.
Incoming tasks that are scheduled from the NetworkInterface's thread are run immediately.
Otherwise they are queued to be run by the NetworkInterface thread when it is available.
ThreadPoolMock
ThreadPoolMock is a ThreadPoolInterface. It is not a mock of a
ThreadPool. It has no configurable stored responses. It has one worker thread and a pointer to a
NetworkInterfaceMock, and with these resources it simulates a thread pool well enough to be used
by a ThreadPoolTaskExecutor in unit tests.