Class Pool

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< Pool >

Class Documentation

class Pool : public std::enable_shared_from_this<Pool>

A group of threads to execute tasks.

Public Functions

template<typename F, typename ...Args, typename R = std::invoke_result_t<F&&, Args&&...>>
Future<R> submit(F &&func, Args&&... args)

Submit a tracked task into the pool.

Template Parameters:
  • F – Function type

  • Args – Arguments to the function

  • R – Function return type

Parameters:
  • func – The function to invoke

  • args – Arguments to pass to the function

template<typename F, typename ...Args>
void submitDetached(F &&func, Args&&... args)

Submit a task into the pool with no result.

Template Parameters:
  • F – Function type

  • Args – Arguments to the function

Parameters:
  • func – The function to invoke

  • args – Arguments to pass to the function

template<std::ranges::input_range Rn, typename F, typename ...ExArgs, typename I = std::ranges::range_value_t<Rn>, typename R = std::invoke_result_t<F&&, I, ExArgs&&...>>
MultiFuture<R> batch(const Rn &src, F &&func, ExArgs&&... exargs)

Submit a tracked batch job based on a container into the pool.

Template Parameters:
  • Rn – Source data container type

  • I – Type of elements in container

  • F – Function type

  • ExArgs – Extra arguments to the function

  • R – Function return type

Parameters:
  • src – The source range to iterate over

  • func – The function to invoke

  • exargs – Extra arguments to pass to the function

template<std::ranges::input_range Rn, typename F, typename ...ExArgs, typename I = std::ranges::range_value_t<Rn>>
void batchDetached(const Rn &src, F &&func, ExArgs&&... exargs)

Submit a batch job based on a container into the pool with no result.

Template Parameters:
  • Rn – Source data container type

  • I – Type of elements in container

  • F – Function type

  • ExArgs – Extra arguments to the function

Parameters:
  • src – The source range to iterate over

  • func – The function to invoke

  • exargs – Extra arguments to pass to the function

std::size_t getThreadCount() const noexcept

Get the number of worker threads managed the pool.

Returns:

Pool thread count

void waitIdle() const noexcept

Wait until there are no more tasks in the queue (tasks submitted during this call will continue to block it)

~Pool()

Public Static Functions

static std::shared_ptr<Pool> Create(std::size_t threadCount = std::thread::hardware_concurrency() / 2)

Create a new pool with a set amount of threads.

Parameters:

threadCount – The number of threads to assign to the pool (half of the hardware concurrency by default)

Throws:

std::out_of_range – If the amount of threads consumed by all pools would exceed std::thread::hardware_concurrency if this pool were created

Friends

friend struct details::YieldOp
friend struct details::VoidPromise
friend struct details::ValuePromise