boost::capy::thread_pool

A pool of threads for executing work concurrently.

Synopsis

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: Unsafe.

Example

thread_pool pool(4);  // 4 worker threads
auto ex = pool.get_executor();
ex.post(some_coroutine);
// pool destructor waits for all work to complete

Base Classes

Name Description

execution_context

Base class for I/O object containers providing service management.

Types

Name

Description

executor_type

An executor that submits work to a thread_pool.

service

Abstract base class for services owned by an execution context.

Member Functions

Name

Description

thread_pool [constructor] [deleted]

Construct a thread pool.

~thread_pool [destructor]

Destroy the thread pool.

operator= [deleted]

Assignment operators

find_service

Return a pointer to the service of type T, or nullptr.

get_executor

Return an executor for this thread pool.

get_frame_allocator

Return the memory resource used for coroutine frame allocation.

has_service

Return true if a service of type T exists.

make_service

Construct and add a service.

set_frame_allocator

set_frame_allocator overloads

stop

Request all worker threads to stop.

target

Return a pointer to this context if it matches the requested type.

use_service

Return a reference to the service of type T, creating it if needed.

Protected Member Functions

Name

Description

destroy

Destroy all services.

shutdown

Shut down all services.

Non-Member Functions

Name

Description

get_system_context

Return the process‐wide system execution context.

Created with MrDocs