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
- Host: GitHub
- URL: https://github.com/cppplayground/simple-threadpool
- Owner: CppPlayground
- License: mit
- Created: 2023-06-20T19:25:55.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-20T20:01:51.000Z (about 3 years ago)
- Last Synced: 2025-01-20T15:59:26.336Z (over 1 year ago)
- Topics: cpp, cpp11, cpp14, cpp17, cpp20, header-only, thread-pool
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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;
}
```