|
| | thread_pool_backend_base (size_t num_threads=default_worker_count(), bool register_workers=false) |
| | thread_pool_backend_base (thread_pool_backend_base const &)=delete |
| auto | operator= (thread_pool_backend_base const &) -> thread_pool_backend_base &=delete |
| | ~thread_pool_backend_base () |
| template<typename F, typename... Args> |
| auto | try_submit (F &&f, Args &&... args) -> expected< std::future< bind_result_t< F, Args... > >, std::error_code > |
| | Submit a task without throwing on shutdown.
|
| template<typename F, typename... Args> |
| auto | submit (F &&f, Args &&... args) -> std::future< bind_result_t< F, Args... > > |
| | Submit a task, throwing on shutdown.
|
| template<typename F, typename... Args> |
| void | post (F &&f, Args &&... args) |
| | Fire-and-forget task submission (throwing variant).
|
| template<typename F, typename... Args> |
| auto | try_post (F &&f, Args &&... args) -> expected< void, std::error_code > |
| | Fire-and-forget task submission (non-throwing variant).
|
| template<typename Iterator> |
| auto | try_submit_batch (Iterator begin, Iterator end) -> expected< std::vector< std::future< void > >, std::error_code > |
| | Submit a range of void() callables in one go (non-throwing).
|
| template<typename Iterator> |
| auto | submit_batch (Iterator begin, Iterator end) -> std::vector< std::future< void > > |
| | Submit a batch of tasks (throwing).
|
| template<typename Iterator, typename F> |
| void | parallel_for_each (Iterator begin, Iterator end, F &&func) |
| | Apply func to [begin, end) in parallel (chunked).
|
| auto | size () const noexcept -> size_t |
| | Number of worker threads.
|
| auto | pending_tasks () const -> size_t |
| | Number of tasks waiting in the queue.
|
| auto | get_statistics () const -> statistics |
| | Collect approximate performance counters.
|
| auto | configure_threads (std::string const &name_prefix, native_scheduling_policy policy=native_scheduling_policy::other, native_thread_priority priority=native_thread_priority::normal()) -> expected< void, std::error_code > |
| | Name, schedule and prioritize all worker threads.
|
| auto | configure_threads (native_thread_config const &config) -> expected< void, std::error_code > |
| auto | set_affinity (native_thread_affinity const &affinity) -> expected< void, std::error_code > |
| | Pin all workers to the same CPU set.
|
| auto | distribute_across_cpus () -> expected< void, std::error_code > |
| | Pin each worker to a distinct CPU core (round-robin).
|
| void | wait_for_tasks () |
| | Block until all pending and active tasks have completed.
|
| auto | is_current_worker () const noexcept -> bool |
| void | shutdown (shutdown_policy_backend policy=shutdown_policy_backend::drain) |
| | Shut the pool down.
|
| auto | shutdown_for (std::chrono::milliseconds timeout) -> bool |
| | Attempt a timed drain: finish as many tasks as possible within timeout, then discard queued work.
|
| void | set_on_task_start (task_start_callback cb) |
| | Register a callback invoked just before each task executes.
|
| template<typename Callback, std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< Callback >, task_start_callback >, int > = 0> |
| void | set_on_task_start (Callback &&cb) |
| void | set_on_task_end (task_end_callback cb) |
| | Register a callback invoked just after each task completes.
|
| template<typename Callback, std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< Callback >, task_end_callback >, int > = 0> |
| void | set_on_task_end (Callback &&cb) |
template<typename WaitPolicy>
class threadschedule::detail::thread_pool_backend_base< WaitPolicy >
Single-queue thread pool parameterized by its idle-wait strategy.
All tasks share one std::queue protected by a single mutex. The WaitPolicy template parameter controls how workers wait for new work:
- How task execution works
- When you call submit(), the callable is wrapped in a std::packaged_task, pushed into the shared task queue under a mutex lock, and one sleeping worker is woken via condition_variable::notify_one(). The woken worker pops the front element and executes it.
- Execution guarantees
- Every successfully submitted task (submit() returned without throwing) is guaranteed to eventually execute.
- submit() throws std::runtime_error if the pool is already shutting down. In that case the task is NOT enqueued.
- Tasks are stored in a FIFO queue. Multiple workers pop concurrently, so submission order is roughly preserved but completion order is non-deterministic.
- The returned std::future becomes ready once the task finishes. If the task threw an exception, future.get() rethrows it.
- On shutdown(), workers finish their current task, then drain all remaining queued tasks before exiting.
- wait_for_tasks() blocks until the queue is empty AND no worker is currently executing a task.
- Thread safety
- submit() and submit_batch() may be called from any thread concurrently. shutdown() is internally guarded and safe to call more than once.
- Exception handling
- Exceptions thrown by tasks are caught inside the worker loop. They are stored in the std::future returned by submit(). The worker thread continues processing.
- Lifetime
- The destructor calls shutdown() and joins all worker threads. Can block if tasks are still running.
- Copyability / movability
- Not copyable, not movable.
- Template Parameters
-
| WaitPolicy | Strategy type with a static wait(cv, lock, predicate) -> bool method. |
Definition at line 97 of file thread_pool_backend_base.hpp.