C++11 simple threadpool example
- CMake > 3.16
- Boost > 1.65
- C++11 compatible compiler
- Clone repository
git clone <url>
- Enter project directory
cd threadpool-example
- Run CMake
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RELEASE
- Build
cmake --build build
build folder now contains threadpool_demo executable - demo application for threadpool usage
Demo application computes matrix x vector multiplication in parallel with help of threadpool. Matrix and vector are generated randomly using uniform distribution.
Program options:
- threads_num,t - number of used threads
- verbose,v - print matrix, vector and result
- matrix_rows - number of rows in matrix
- matrix_cols - number of cols in matrix
- Create threadpool with desired number of threads
threadpool_example::ThreadPool thp(threadsNum);
- Push task to threadpool and get future result
auto future = thp.enqueue([](){
std::cout << "I am a task";
return 0;
});
- Optionaly wait for future result
std::cout << "result is " << future.get();