An open API service indexing awesome lists of open source software.

https://github.com/cppplayground/simple-threadpool

a simple and lightweight header only ThreadPool for your tasks
https://github.com/cppplayground/simple-threadpool

cpp cpp11 cpp14 cpp17 cpp20 header-only thread-pool

Last synced: 6 months ago
JSON representation

a simple and lightweight header only ThreadPool for your tasks

Awesome Lists containing this project

README

          

# Header only simple thread pool

> put your tasks into threads

## How to use it

```c++
#include "ThreadPool.h"
#include

void printNumber(int number) { std::cout << "Number: " << number << std::endl; }

int main() {
ThreadPool pool(4);

std::vector> results;

// starting the threads
for (int i = 0; i < 8; ++i) {
results.emplace_back(pool.enqueue(printNumber, i));
}

// getting the results
for (auto &&result : results) {
result.get();
}

return 0;
}
```

multiply example

```c++
#include "ThreadPool.h"
#include

int multiply(const int a, const int b) {
return a * b;
}

int main() {
ThreadPool pool(12);

std::future result = pool.enqueue(multiply, 3, 5);

std::cout<< result.get();

return 0;
}
```