![]() |
Libftpp
A modern C++ library
|
Persistent worker thread that executes tasks in a continuous loop. More...
#include <persistent_worker.hpp>
Public Member Functions | |
| PersistentWorker () | |
| ~PersistentWorker () | |
| void | addTask (const std::string &name, const std::function< void()> &jobToExecute) |
| void | removeTask (const std::string &name) |
Persistent worker thread that executes tasks in a continuous loop.
This class provides a background worker thread that continuously executes registered tasks in a loop. Tasks can be dynamically added and removed during runtime, making it ideal for background processing, periodic operations, or event-driven task execution. The worker uses condition variables for efficient thread synchronization and CPU usage.
Thread-safe task management using mutex and condition variables
Automatically starts worker thread on construction and stops on destruction
Worker thread sleeps when no tasks are available, reducing CPU usage
Definition at line 57 of file persistent_worker.hpp.
| PersistentWorker::PersistentWorker | ( | ) |
Definition at line 3 of file persistent_worker.cpp.
| PersistentWorker::~PersistentWorker | ( | ) |
Definition at line 8 of file persistent_worker.cpp.
| void PersistentWorker::addTask | ( | const std::string & | name, |
| const std::function< void()> & | jobToExecute | ||
| ) |
Definition at line 19 of file persistent_worker.cpp.
| void PersistentWorker::removeTask | ( | const std::string & | name | ) |
Definition at line 26 of file persistent_worker.cpp.