A thread loop that can be paused, resumed, and stopped. More...
#include <pausable_thread_loop.hpp>
Public Member Functions | |
| PausableThreadLoop (std::function< void()> func, Duration sleep=std::chrono::seconds{0}) | |
| Constructs a thread to run the specified function in a loop. More... | |
| bool | is_running () const noexcept |
| Checks if the thread is currently running (not paused or stopped). More... | |
| void | pause_nb () noexcept |
| Pauses the execution of the thread. More... | |
| void | pause () noexcept |
| Pauses the execution of the thread. More... | |
| bool | resume () noexcept |
| Resumes execution of the thread after being paused. More... | |
| bool | stop () noexcept |
| Stops the execution of the thread and joins it. More... | |
A thread loop that can be paused, resumed, and stopped.
This class runs a provided function repeatedly in a separate thread.
Definition at line 21 of file pausable_thread_loop.hpp.
| rapidsmpf::detail::PausableThreadLoop::PausableThreadLoop | ( | std::function< void()> | func, |
| Duration | sleep = std::chrono::seconds{0} |
||
| ) |
Constructs a thread to run the specified function in a loop.
The loop will execute the given function repeatedly in a separate thread. The thread starts in a paused state and will remain paused until the resume() method is called.
If a sleep duration is provided, the thread will sleep for the specified duration between executions of the task.
A short sleep is introduced when running under Valgrind to avoid potential issues with thread starvation.
| func | The function to execute repeatedly in the thread. |
| sleep | The duration to sleep between executions of the task. By default, the thread yields execution instead of sleeping. |
|
noexcept |
Checks if the thread is currently running (not paused or stopped).
|
noexcept |
Pauses the execution of the thread.
The thread will stop executing the loop function until resume() is called.
|
noexcept |
Pauses the execution of the thread.
The thread will stop executing the loop function until resume() is called.
pause_nb the thread is not paused until the state has changed to State::PAUSED, so immediately notifying a thread that is waiting on is_running will not necessarily wake it.
|
noexcept |
Resumes execution of the thread after being paused.
Calling resume on an already running loop is a no-op and is allowed.
|
noexcept |
Stops the execution of the thread and joins it.
Once stopped, the thread cannot be resumed.