ThreadSchedule 2.2.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::InlinePool Class Reference

A pool that executes every task inline on the calling thread. More...

#include <inline_pool.hpp>

Public Member Functions

 InlinePool (size_t=0)
template<typename F, typename... Args>
auto submit (F &&f, Args &&... args) -> std::future< std::invoke_result_t< F, Args... > >
template<typename F, typename... Args>
auto try_submit (F &&f, Args &&... args) -> expected< std::future< std::invoke_result_t< F, Args... > >, std::error_code >
template<typename F, typename... Args>
void post (F &&f, Args &&... args)
template<typename F, typename... Args>
auto try_post (F &&f, Args &&... args) -> expected< void, std::error_code >
template<typename Iterator>
auto try_submit_batch (Iterator begin, Iterator end) -> expected< std::vector< std::future< void > >, std::error_code >
template<typename Iterator>
auto submit_batch (Iterator begin, Iterator end) -> std::vector< std::future< void > >
template<typename Iterator, typename F>
void parallel_for_each (Iterator begin, Iterator end, F &&func)
auto size () const noexcept -> size_t
auto pending_tasks () const noexcept -> size_t
void wait_for_tasks ()
void shutdown (ShutdownPolicy=ShutdownPolicy::drain)

Detailed Description

A pool that executes every task inline on the calling thread.

Useful for deterministic unit testing: tasks run synchronously in submission order with no concurrency, making results fully reproducible and debuggable.

API compatibility
InlinePool provides the same submit/try_submit/post/try_post/ submit_batch/parallel_for_each surface as ThreadPool. The returned futures are always already fulfilled when submit() returns.
Limitations
  • size() always returns 0 (no worker threads).
  • shutdown() and wait_for_tasks() are no-ops.
  • There is no concurrency; tasks that block or deadlock will block the submitting thread.

Definition at line 42 of file inline_pool.hpp.

Constructor & Destructor Documentation

◆ InlinePool()

threadschedule::InlinePool::InlinePool ( size_t = 0)
inlineexplicit

Definition at line 45 of file inline_pool.hpp.

Member Function Documentation

◆ parallel_for_each()

template<typename Iterator, typename F>
void threadschedule::InlinePool::parallel_for_each ( Iterator begin,
Iterator end,
F && func )
inline

Definition at line 143 of file inline_pool.hpp.

◆ pending_tasks()

auto threadschedule::InlinePool::pending_tasks ( ) const -> size_t
inlinenodiscardnoexcept

Definition at line 150 of file inline_pool.hpp.

◆ post()

template<typename F, typename... Args>
void threadschedule::InlinePool::post ( F && f,
Args &&... args )
inline

Definition at line 87 of file inline_pool.hpp.

References try_post().

◆ shutdown()

void threadschedule::InlinePool::shutdown ( ShutdownPolicy = ShutdownPolicy::drain)
inline

Definition at line 153 of file inline_pool.hpp.

References threadschedule::drain.

◆ size()

auto threadschedule::InlinePool::size ( ) const -> size_t
inlinenodiscardnoexcept

Definition at line 149 of file inline_pool.hpp.

◆ submit()

template<typename F, typename... Args>
auto threadschedule::InlinePool::submit ( F && f,
Args &&... args ) -> std::future<std::invoke_result_t<F, Args...>>
inline

Definition at line 50 of file inline_pool.hpp.

References try_submit().

◆ submit_batch()

template<typename Iterator>
auto threadschedule::InlinePool::submit_batch ( Iterator begin,
Iterator end ) -> std::vector<std::future<void>>
inline

Definition at line 134 of file inline_pool.hpp.

References try_submit_batch().

◆ try_post()

template<typename F, typename... Args>
auto threadschedule::InlinePool::try_post ( F && f,
Args &&... args ) -> expected<void, std::error_code>
inline

Definition at line 95 of file inline_pool.hpp.

Referenced by post().

◆ try_submit()

template<typename F, typename... Args>
auto threadschedule::InlinePool::try_submit ( F && f,
Args &&... args ) -> expected<std::future<std::invoke_result_t<F, Args...>>, std::error_code>
inline

Definition at line 59 of file inline_pool.hpp.

Referenced by submit().

◆ try_submit_batch()

template<typename Iterator>
auto threadschedule::InlinePool::try_submit_batch ( Iterator begin,
Iterator end ) -> expected<std::vector<std::future<void>>, std::error_code>
inline

Definition at line 110 of file inline_pool.hpp.

Referenced by submit_batch().

◆ wait_for_tasks()

void threadschedule::InlinePool::wait_for_tasks ( )
inline

Definition at line 152 of file inline_pool.hpp.


The documentation for this class was generated from the following file: