|
ThreadSchedule 3.0.0
Modern C++ thread management library
|
Fixed-size thread pool for queued asynchronous work. More...
#include <thread_pool.hpp>
Public Member Functions | |
| thread_pool () | |
| Construct a pool with default configuration. | |
| thread_pool (worker_count count) | |
| Construct a pool with explicit worker count. | |
| thread_pool (thread_pool_config config) | |
| Construct a pool from full configuration. | |
| thread_pool (thread_pool &&) noexcept=default | |
| auto | operator= (thread_pool &&other) noexcept -> thread_pool & |
| thread_pool (thread_pool const &)=delete | |
| auto | operator= (thread_pool const &) -> thread_pool &=delete |
| ~thread_pool () | |
| Shutdown the pool according to configured policy. | |
| template<typename F , typename... Args> | |
| auto | submit (F &&function, Args &&... args) -> result< std::future< detail::bind_result_t< F, Args... > > > |
| Submit work and receive a future for its result. | |
| template<typename F , typename... Args> | |
| auto | submit_or_throw (F &&function, Args &&... args) -> std::future< detail::bind_result_t< F, Args... > > |
| Throwing counterpart to submit. | |
| template<typename F , typename... Args> | |
| auto | post (F &&function, Args &&... args) -> result< void > |
| Post fire-and-forget work to the pool. | |
| template<typename F , typename... Args> | |
| void | post_or_throw (F &&function, Args &&... args) |
| Throwing counterpart to post. | |
| auto | wait () -> result< void > |
| Wait until all queued/running tasks are finished. | |
| void | wait_or_throw () |
| Throwing counterpart to wait. | |
| auto | configure_workers (thread_config const &config) -> result< void > |
| Apply thread configuration to all workers. | |
| auto | shutdown () -> result< void > |
| Shutdown using configured policy. | |
| auto | shutdown (shutdown_policy policy) -> result< void > |
| Shutdown with explicit policy. | |
| auto | size () const noexcept -> std::size_t |
| Return configured worker count (0 if moved-from; retained after shutdown). | |
Static Public Member Functions | |
| static auto | create (thread_pool_config config={}) -> result< thread_pool > |
| Create a pool without throwing. | |
Fixed-size thread pool for queued asynchronous work.
Definition at line 114 of file thread_pool.hpp.
|
inline |
Construct a pool with default configuration.
Definition at line 118 of file thread_pool.hpp.
|
inlineexplicit |
Construct a pool with explicit worker count.
| count | Number of workers or automatic resolution mode. |
Definition at line 124 of file thread_pool.hpp.
|
inlineexplicit |
Construct a pool from full configuration.
| config | Pool configuration. |
| std::system_error | if worker configuration cannot be applied. |
Definition at line 131 of file thread_pool.hpp.
References threadschedule::thread_pool_config::get_worker_config(), threadschedule::detail::has_thread_configuration(), and threadschedule::detail::to_native().
|
defaultnoexcept |
|
delete |
|
inline |
Shutdown the pool according to configured policy.
Destructor never throws and will attempt best-effort shutdown.
Definition at line 175 of file thread_pool.hpp.
|
inline |
Apply thread configuration to all workers.
| config | Portable configuration to apply. |
Definition at line 332 of file thread_pool.hpp.
References threadschedule::detail::to_native(), and threadschedule::detail::try_result().
|
inlinestatic |
Create a pool without throwing.
| config | Pool configuration. |
Definition at line 165 of file thread_pool.hpp.
|
inlinenoexcept |
Definition at line 146 of file thread_pool.hpp.
|
delete |
|
inline |
Post fire-and-forget work to the pool.
| function | Callable to execute. |
| args | Arguments forwarded to the callable. |
Definition at line 254 of file thread_pool.hpp.
References threadschedule::detail::bind_args(), threadschedule::task_error::capture(), threadschedule::thread_pool_config::get_error_callback(), and threadschedule::detail::try_result().
Referenced by post_or_throw().
|
inline |
Throwing counterpart to post.
| std::system_error | if posting fails. |
Definition at line 293 of file thread_pool.hpp.
References post().
|
inline |
Shutdown using configured policy.
Definition at line 343 of file thread_pool.hpp.
References threadschedule::thread_pool_config::get_shutdown_policy(), and shutdown().
Referenced by shutdown().
|
inline |
Shutdown with explicit policy.
| policy | Drain/cancel behavior used for pending tasks. |
Definition at line 353 of file thread_pool.hpp.
References threadschedule::detail::to_native(), and threadschedule::detail::try_result().
|
inlinenoexcept |
Return configured worker count (0 if moved-from; retained after shutdown).
Definition at line 367 of file thread_pool.hpp.
|
inline |
Submit work and receive a future for its result.
| function | Callable to execute on a worker. |
| args | Arguments forwarded to the callable. |
Definition at line 188 of file thread_pool.hpp.
References threadschedule::detail::bind_args(), threadschedule::task_error::capture(), threadschedule::thread_pool_config::get_error_callback(), and threadschedule::detail::try_result().
Referenced by submit_or_throw().
|
inline |
Throwing counterpart to submit.
| std::system_error | if submission fails. |
Definition at line 238 of file thread_pool.hpp.
References submit().
|
inline |
Wait until all queued/running tasks are finished.
Definition at line 304 of file thread_pool.hpp.
References threadschedule::detail::try_result().
|
inline |
Throwing counterpart to wait.
Definition at line 320 of file thread_pool.hpp.