This is a simple C++ Task Scheduler that allows you to schedule and run tasks at fixed intervals using multithreading.
It is designed with an abstract Task interface, a concrete IntervalTask, and a TaskScheduler that manages and runs tasks safely across threads.
- Define custom tasks by extending the
Taskclass. - Run functions at fixed intervals (
IntervalTask). - Safe multithreaded scheduling with
std::mutex. - Easy to extend and integrate into other C++ projects.
git clone https://github.com/Abdulkhalek-1/Cpp-Scheduler.git
cd ./Cpp-Schedulerg++ -std=c++17 -pthread main.cpp -o scheduler./schedulerYou will see output like:
Checking Steam Prices...
Checking Udemy Prices...
...
Tasks will automatically execute at the intervals you define.
scheduler.add_task(std::make_shared<IntervalTask>(
[] { std::cout << "Fetching latest news...\n"; }, 15)); // every 15 secondsYou can pass any function or lambda that matches void().
- C++17 or newer
- A POSIX-compatible system (Linux, Mac) or Windows with
g++or compatible compiler.
Feel free to use and modify this code for personal or commercial projects.