Classes | Public Types | Public Member Functions | List of all members
rapidsmpf::ProgressThread Class Reference

A progress thread that can execute arbitrary functions. More...

#include <progress_thread.hpp>

Classes

struct  FunctionID
 The unique ID of a function registered with ProgressThread. Composed of the ProgressThread address and a sequential function index. More...
 
class  FunctionState
 Store state of a function. More...
 

Public Types

enum  ProgressState : bool { InProgress , Done }
 The progress state of a function, can be either InProgress or Done.
 
using FunctionIndex = std::uint64_t
 The sequential index of a function within a ProgressThread.
 
using ProgressThreadAddress = std::uintptr_t
 The address of a ProgressThread instance.
 
using Function = std::function< ProgressState()>
 The function type supported by ProgressThread, returning the progress state of the function.
 

Public Member Functions

 ProgressThread (Communicator::Logger &logger, std::shared_ptr< Statistics > statistics=Statistics::disabled(), Duration sleep=std::chrono::microseconds{1})
 Construct a new progress thread that can handle multiple functions. More...
 
void stop ()
 Stop the thread, blocking until all functions are done.
 
FunctionID add_function (Function &&function)
 Insert a function to process as part of the event loop. More...
 
void remove_function (FunctionID function_id)
 Remove a function and stop processing it as part of the event loop. More...
 
void pause ()
 Pause the progress thread. More...
 
void resume ()
 Resume the progress thread.
 
bool is_running () const
 Check if the progress thread is currently running. More...
 

Detailed Description

A progress thread that can execute arbitrary functions.

Execute each of the registered arbitrary functions in a separate thread. The functions are executed in the order they were registered, and a newly registered function will only execute for the first time in the next iteration of the progress thread.

Definition at line 27 of file progress_thread.hpp.

Constructor & Destructor Documentation

◆ ProgressThread()

rapidsmpf::ProgressThread::ProgressThread ( Communicator::Logger logger,
std::shared_ptr< Statistics statistics = Statistics::disabled(),
Duration  sleep = std::chrono::microseconds{1} 
)

Construct a new progress thread that can handle multiple functions.

Parameters
loggerThe logger instance to use.
statisticsThe statistics instance to use (disabled by default).
sleepThe duration to sleep between each progress loop iteration. If 0, the thread yields execution instead of sleeping. Anecdotally, a 1 us sleep time (the default) is sufficient to avoid starvation and get smooth progress.

Member Function Documentation

◆ add_function()

FunctionID rapidsmpf::ProgressThread::add_function ( Function &&  function)

Insert a function to process as part of the event loop.

Note
This function does not need to be thread-safe if not used in multiple progress threads.
Parameters
functionThe function to register.
Returns
The unique ID of the function that was registered.

◆ is_running()

bool rapidsmpf::ProgressThread::is_running ( ) const

Check if the progress thread is currently running.

Returns
true if the thread is running, false otherwise.

◆ pause()

void rapidsmpf::ProgressThread::pause ( )

Pause the progress thread.

Note
This blocks until the thread is actually paused.

◆ remove_function()

void rapidsmpf::ProgressThread::remove_function ( FunctionID  function_id)

Remove a function and stop processing it as part of the event loop.

This function blocks until the function is done (returning ProgressState::Done).

Parameters
function_idThe unique function ID returned by add_function.
Exceptions
std::logic_errorif the function was not registered with this ProgressThread or was already removed.

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