boost::capy::thread_pool
Distributes posted work across a fixed group of worker threads via a shared queue.
Synopsis
Declared in <boost/capy/ex/thread_pool.hpp>
class thread_pool
: public execution_context
Description
Use this when you need to run coroutines on multiple threads without the overhead of creating and destroying threads for each task. Work items are distributed across the pool using a shared queue.
Thread Safety
Distinct objects: Safe. Shared objects: Safe for get_executor, join, and stop. Unsafe for construction and destruction.
Example
capy::task<void> some_task() { co_return; }
void run_on_pool()
{
capy::thread_pool pool(4); // 4 worker threads
auto ex = pool.get_executor();
capy::run_async(ex)(some_task()); // start work; tracked so join() waits for it
pool.join(); // wait for outstanding work to complete
// pool destructor stops the pool and abandons any work still queued
}
|
|
Base Classes
Name |
Description |
Registers, looks up, and shuts down |
Types
Name |
Description |
Runs continuations on the worker threads of a thread_pool. |
|
Gives a derived service a |
Member Functions
Name |
Description |
|
Constructors |
|
Destroy the thread pool. |
Assignment operators |
|
Return a pointer to the service of type T, or nullptr. |
|
Return an executor for this thread pool. |
|
Return the memory resource used for coroutine frame allocation. |
|
Return true if a service of type T exists. |
|
Wait for all outstanding work to complete. |
|
Construct and add a service. |
|
|
|
Request all worker threads to stop. |
|
Return a pointer to this context if it matches the requested type. |
|
Return a reference to the service of type T, creating it if needed. |
Non-Member Functions
Name |
Description |
Return the process‐wide system thread pool. |
Created with MrDocs