# thread_pool **Repository Path**: tianfuzeng/thread_pool ## Basic Information - **Project Name**: thread_pool - **Description**: C++ thread pool library - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-07-30 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Thread pool [![Latest GitHub release](https://img.shields.io/github/release/rvaser/thread_pool.svg)](https://github.com/rvaser/thread_pool/releases/latest) [![Build status for c++/clang++](https://travis-ci.org/rvaser/thread_pool.svg?branch=master)](https://travis-ci.org/rvaser/thread_pool) ThreadPool is a c++ header only library modifying and extending https://github.com/progschj/ThreadPool. ## Usage If you would like to add thread_pool to your project via CMake, add the following: ```cmake if (NOT TARGET thread_pool) add_subdirectory(/thread_pool EXCLUDE_FROM_ALL) endif () target_link_libraries( thread_pool) ``` If you are not using CMake, include the appropriate header file directly to your project and link with pthread. #### Dependencies - gcc 4.8+ or clang 3.5+ - (optional) cmake 3.9+ ## Examples ```cpp #include "thread_pool/thread_pool.hpp" int function1(const T& t, ...) { ... } int function2(...) { ... } ... auto lambda1 = [...] (...) -> void { ... }; ThreadPool thread_pool{}; std::vector> futures; for (...) { // be sure to used std::ref() or std::cref() for references futures.emplace_back(thread_pool.Submit(function1, std::cref(t), ...)); futures.emplace_back(thread_pool.Submit(function2, ...)); } for (auto& it : futures) { ... = it.get(); } std::vector> void_futures; for (...) { void_futures.emplace_back(thread_pool.Submit(lambda1, ...)); } for (const auto& it : void_futures) { it.wait(); } ``` ## Unit tests To build and run thread_pool unit tests run the following commands: ```bash git clone https://github.com/rvaser/thread_pool.git thread_pool cd thread_pool && mkdir build && cd build cmake -Dthread_pool_build_tests=ON -DCMAKE_BUILD_TYPE=Release .. && make ./bin/thread_pool_test ``` #### Dependencies - gtest ## Acknowledgement This work has been supported in part by the Croatian Science Foundation under the project Single genome and metagenome assembly (IP-2018-01-5886).