Public Member Functions | List of all members
rapidsmpf::streaming::CoroThreadPoolExecutor Class Reference

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
 
CoroThreadPoolExecutoroperator= (CoroThreadPoolExecutor &o)=delete
 
CoroThreadPoolExecutoroperator= (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...
 

Detailed Description

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.

Warning
Shutdown of the executor must be initiated from the same thread that created it. Calling 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.

Constructor & Destructor Documentation

◆ CoroThreadPoolExecutor() [1/2]

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.

Parameters
num_streaming_threadsNumber of threads used to execute coroutines. Must be greater than zero.
statisticsStatistics 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.

◆ CoroThreadPoolExecutor() [2/2]

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.

Parameters
optionsConfiguration options used to initialize the executor.
statisticsStatistics 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.
Exceptions
std::invalid_argumentIf num_streaming_threads is present but not a positive integer.

Member Function Documentation

◆ get()

std::unique_ptr<coro::thread_pool>& rapidsmpf::streaming::CoroThreadPoolExecutor::get ( )
noexcept

Get access to the underlying thread pool to be used with libcoro.

Returns
Reference to the owning std::unique_ptr holding the coro::thread_pool.
Note
Ownership of the thread pool remains with the executor.

◆ num_streaming_threads()

std::uint32_t rapidsmpf::streaming::CoroThreadPoolExecutor::num_streaming_threads ( ) const
inlinenoexcept

Get the configured number of streaming threads.

Returns
Number of threads in the underlying libcoro thread pool.

Definition at line 98 of file coro_executor.hpp.

◆ schedule() [1/2]

auto rapidsmpf::streaming::CoroThreadPoolExecutor::schedule ( )
inline

Schedule work on the underlying libcoro thread pool.

Returns
A libcoro awaitable as returned by coro::thread_pool::schedule().

Definition at line 116 of file coro_executor.hpp.

◆ schedule() [2/2]

auto rapidsmpf::streaming::CoroThreadPoolExecutor::schedule ( auto  task)
inline

Schedule a task on the underlying libcoro thread pool.

Parameters
taskTask to schedule.
Returns
A libcoro awaitable as returned by coro::thread_pool::schedule(task).

Definition at line 126 of file coro_executor.hpp.

◆ shutdown()

void rapidsmpf::streaming::CoroThreadPoolExecutor::shutdown ( )
noexcept

Shut down the underlying thread pool.

This method is idempotent and only performs shutdown once. Subsequent calls have no effect.

Warning
Shutdown must be initiated from the same thread that constructed the executor. Calling this method from a different thread results in program termination.

◆ spawn_detached()

auto rapidsmpf::streaming::CoroThreadPoolExecutor::spawn_detached ( auto  task)
inlinenoexcept

Spawn a detached task on the underlying libcoro thread pool.

Parameters
taskTask to spawn.
Returns
Result as returned by coro::thread_pool::spawn_detached(task).

Definition at line 145 of file coro_executor.hpp.

◆ spawn_joinable()

auto rapidsmpf::streaming::CoroThreadPoolExecutor::spawn_joinable ( auto  task)
inlinenoexcept

Spawn a joinable task on the underlying libcoro thread pool.

Parameters
taskTask to spawn.
Returns
Result as returned by coro::thread_pool::spawn_joinable(task).

Definition at line 155 of file coro_executor.hpp.

◆ yield()

auto rapidsmpf::streaming::CoroThreadPoolExecutor::yield ( )
inline

Yield execution back to the underlying libcoro thread pool.

Returns
A libcoro awaitable as returned by coro::thread_pool::yield().

Definition at line 135 of file coro_executor.hpp.


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