https://github.com/tastyep/taskmanager
A C++14 Task Manager / Scheduler
https://github.com/tastyep/taskmanager
async asynchronous cpp multithreading task-manager task-scheduler taskmanager thread-pool workers
Last synced: 6 months ago
JSON representation
A C++14 Task Manager / Scheduler
- Host: GitHub
- URL: https://github.com/tastyep/taskmanager
- Owner: Tastyep
- License: mit
- Created: 2015-07-05T09:21:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-08-02T17:49:59.000Z (about 2 years ago)
- Last Synced: 2025-03-27T00:54:14.192Z (6 months ago)
- Topics: async, asynchronous, cpp, multithreading, task-manager, task-scheduler, taskmanager, thread-pool, workers
- Language: C++
- Homepage:
- Size: 352 KB
- Stars: 105
- Watchers: 9
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://travis-ci.org/Tastyep/TaskManager)
TaskManager is an asynchronous task management library using the features of C++14.
### Requirements
A compiler supporting the C++14 features.### Features
###### Components
* A ThreadPool, manages workers (threads).
* A Task manager for running tasks asynchronously.
* A Scheduler for scheduling tasks asynchronously.###### Interface
* The library exposes a module with free functions for creating managers and schedulers.### Documentation
Online documentation can be found [here](https://tastyep.github.io/TaskManager/API/html/index.html).The documentation is generated using [Doxygen](https://www.stack.nl/~dimitri/doxygen/) which means it can also be found in the source code.
Note: Files located in the detail/ directories are left undocumented as they are not exposed and only used internally.
### Basic Usage
###### ManagerNote: The following examples use chrono literals.
```C++
// Create the thread pool with the initial number of threads (2 here).
Task::Module::init(2);// Create a task manager with one worker.
auto manager = Task::Module::makeManager(1);// Add a new task and get its future.
auto future = manager.push([] { return 42; });// Get the result from the future and print it.
std::cout << future.get() << std::endl; // Prints 42// Not necessary here, but the stop method ensures that all launched tasks have been executed.
manager.stop().get();
```In the above example if we were to push more tasks, only one at a time would be executed as the manager has only one worker assigned.
###### Scheduler
```C++
// Create the thread pool with the initial number of threads (2 here).
Task::Module::init(2);// Create a scheduler with one worker.
auto scheduler = Task::Module::makeScheduler(1);// Declare the variable n.
size_t n = 0;// Add new tasks and get the future.
auto future = scheduler.scheduleIn("Task1", 2s, [&n] { n++; });
scheduler.scheduleIn("Task2", 1s, [&n] { n = 41 });// Get the future and print the updated value.
future.get()
std::cout << n << std::endl; // Prints 42// Not necessary here, but the stop method ensures that all the scheduled tasks have been executed.
scheduler.stop().get();
```The same note applies for the scheduler regarding the number of associated workers.
Also an identifier ("TaskX") is provided so that periodic tasks could be removed.