Schedulers

Lazy pool

class lazy_pool

A scheduler based on a An Efficient Work-Stealing Scheduler for Task Dependency Graph

This pool sleeps workers which cannot find any work, as such it should be the default choice for most use cases. Additionally (if an installation of hwloc was found) this pool is NUMA aware.

Note: The lazy_pool must not be destructed until all submitted tasks have reached a point where they will submit no-more work to the pool.

Public Functions

lazy_pool(lazy_pool &&other) noexcept = default

Move construct a new lazy_pool object.

lazy_pool(lazy_pool const &other) = delete

The lazy pool is not copyable.

inline explicit lazy_pool(std::size_t n = std::thread::hardware_concurrency(), numa_strategy strategy = numa_strategy::fan)

Construct a new lazy_pool object and n worker threads.

Parameters:
  • n – The number of worker threads to create, defaults to the number of hardware threads.

  • strategy – The numa strategy for distributing workers.

inline ~lazy_pool() noexcept

Destroy the lazy pool object, stops all workers.

inline auto contexts() noexcept -> std::span<worker_context*>

Get a view of the worker’s contexts.

auto operator=(lazy_pool &&other) noexcept -> lazy_pool& = default

Move assign a lazy_pool object.

auto operator=(lazy_pool const &other) -> lazy_pool& = delete

The lazy pool is not copy assignable.

inline void schedule(submit_handle job)

Schedule a job on a random worker.

Busy pool

class busy_pool

A scheduler based on a traditional work-stealing thread pool.

Worker threads continuously try to steal tasks from other worker threads hence, they waste CPU cycles if sufficient work is not available. This is a good choice if the number of threads is equal to the number of hardware cores and the multiplexer has no other load. Additionally (if an installation of hwloc was found) this pool is NUMA aware.

Note: The busy_pool must not be destructed until all submitted tasks have reached a point where they will submit no-more work to the pool.

Public Functions

busy_pool(busy_pool &&other) noexcept = default

Move construct a new lazy_pool object.

busy_pool(busy_pool const &other) = delete

The busy pool is not copyable.

inline explicit busy_pool(std::size_t n = std::thread::hardware_concurrency(), numa_strategy strategy = numa_strategy::fan)

Construct a new busy_pool object.

Parameters:
  • n – The number of worker threads to create, defaults to the number of hardware threads.

  • strategy – The numa strategy for distributing workers.

inline auto contexts() noexcept -> std::span<worker_context*>

Get a view of the worker’s contexts.

auto operator=(busy_pool &&other) noexcept -> busy_pool& = default

Move assign a lazy_pool object.

auto operator=(busy_pool const &other) -> busy_pool& = delete

The busy pool is not copy assignable.

inline void schedule(submit_handle job)

Schedule a task for execution.

Unit pool

class unit_pool : private lf::impl::immovable<unit_pool>

A scheduler that runs all tasks on a single thread.

This is useful for testing/debugging/benchmarking as it is the only work-pool that can guarantee all the work completes if submitting detached work.