Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Header only simple thread pool

put your tasks into threads

How to use it

#include"ThreadPool.h"
#include<iostream>voidprintNumber(int number) { std::cout << "Number: " << number << std::endl; }
intmain() {
ThreadPool pool(4);
std::vector<std::future<void>> results;
// starting the threadsfor (int i = 0; i < 8; ++i) {
results.emplace_back(pool.enqueue(printNumber, i));
}
// getting the resultsfor (auto &&result : results) {
result.get();
}
return0;
}

multiply example

#include"ThreadPool.h"
#include<iostream>intmultiply(constint a, constint b) {
return a * b;
}
intmain() {
ThreadPool pool(12);
std::future<int> result = pool.enqueue(multiply, 3, 5);
std::cout<< result.get();
return0;
}

About

a simple and lightweight header only ThreadPool for your tasks

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages