Executor wrapper around a coro::thread_pool used for coroutine execution.
More...
#include <coro_executor.hpp>
Public Member Functions | |
| CoroThreadPoolExecutor (std::uint32_t num_streaming_threads, std::shared_ptr< Statistics > statistics=Statistics::disabled()) | |
| Construct an executor with an explicit number of streaming threads. More... | |
| CoroThreadPoolExecutor (config::Options options, std::shared_ptr< Statistics > statistics=Statistics::disabled()) | |
| Construct an executor from configuration options. More... | |
| CoroThreadPoolExecutor (CoroThreadPoolExecutor &&)=delete | |
| No move and copy constructors and assignment operators. | |
| CoroThreadPoolExecutor (CoroThreadPoolExecutor const &)=delete | |
| CoroThreadPoolExecutor & | operator= (CoroThreadPoolExecutor &o)=delete |
| CoroThreadPoolExecutor & | operator= (CoroThreadPoolExecutor &&o)=delete |
| void | shutdown () noexcept |
| Shut down the underlying thread pool. More... | |
| std::uint32_t | num_streaming_threads () const noexcept |
| Get the configured number of streaming threads. More... | |
| std::unique_ptr< coro::thread_pool > & | get () noexcept |
| Get access to the underlying thread pool to be used with libcoro. More... | |
| auto | schedule () |
| Schedule work on the underlying libcoro thread pool. More... | |
| auto | schedule (auto task) |
| Schedule a task on the underlying libcoro thread pool. More... | |
| auto | yield () |
| Yield execution back to the underlying libcoro thread pool. More... | |
| auto | spawn_detached (auto task) noexcept |
| Spawn a detached task on the underlying libcoro thread pool. More... | |
| auto | spawn_joinable (auto task) noexcept |
| Spawn a joinable task on the underlying libcoro thread pool. More... | |
Executor wrapper around a coro::thread_pool used for coroutine execution.
The executor lifetime defines the lifetime of the underlying thread pool. The number of threads can be provided explicitly or derived from configuration options.
shutdown() from a different thread results in program termination. Since the destructor implicitly calls shutdown(), destroying the executor from a different thread also results in termination unless the executor has already been shut down explicitly.This can be subtle in coroutine-based code, where a scheduled coroutine may unwind its stack on a different thread and trigger destructors. Explicitly calling shutdown() on the creator thread allows the destructor to run safely on any thread afterward.
Definition at line 36 of file coro_executor.hpp.
| rapidsmpf::streaming::CoroThreadPoolExecutor::CoroThreadPoolExecutor | ( | std::uint32_t | num_streaming_threads, |
| std::shared_ptr< Statistics > | statistics = Statistics::disabled() |
||
| ) |
Construct an executor with an explicit number of streaming threads.
| num_streaming_threads | Number of threads used to execute coroutines. Must be greater than zero. |
| statistics | Statistics collector associated with the executor. If not provided, statistics collection is disabled. TODO: statistics are not currently collected. In the future, libcoro's thread start and stop callbacks should be used to track coroutine execution statistics. |
| rapidsmpf::streaming::CoroThreadPoolExecutor::CoroThreadPoolExecutor | ( | config::Options | options, |
| std::shared_ptr< Statistics > | statistics = Statistics::disabled() |
||
| ) |
Construct an executor from configuration options.
Reads the num_streaming_threads option. If the option is not set, a single streaming thread is used by default.
| options | Configuration options used to initialize the executor. |
| statistics | Statistics collector associated with the executor. If not provided, statistics collection is disabled. TODO: statistics are not currently collected. In the future, libcoro's thread start and stop callbacks should be used to track coroutine execution statistics. |
| std::invalid_argument | If num_streaming_threads is present but not a positive integer. |
|
noexcept |
Get access to the underlying thread pool to be used with libcoro.
std::unique_ptr holding the coro::thread_pool.
|
inlinenoexcept |
Get the configured number of streaming threads.
Definition at line 98 of file coro_executor.hpp.
|
inline |
Schedule work on the underlying libcoro thread pool.
coro::thread_pool::schedule(). Definition at line 116 of file coro_executor.hpp.
|
inline |
Schedule a task on the underlying libcoro thread pool.
| task | Task to schedule. |
coro::thread_pool::schedule(task). Definition at line 126 of file coro_executor.hpp.
|
noexcept |
Shut down the underlying thread pool.
This method is idempotent and only performs shutdown once. Subsequent calls have no effect.
|
inlinenoexcept |
Spawn a detached task on the underlying libcoro thread pool.
| task | Task to spawn. |
coro::thread_pool::spawn_detached(task). Definition at line 145 of file coro_executor.hpp.
|
inlinenoexcept |
Spawn a joinable task on the underlying libcoro thread pool.
| task | Task to spawn. |
coro::thread_pool::spawn_joinable(task). Definition at line 155 of file coro_executor.hpp.
|
inline |
Yield execution back to the underlying libcoro thread pool.
coro::thread_pool::yield(). Definition at line 135 of file coro_executor.hpp.