Skip to content

Repository files navigation

ThreadPool pipeline status

A simple C++17 Thread Pool implementation.

Basic usage

// create thread pool with 4 worker threads
ThreadPool pool(4);
// enqueue and store futureauto result = pool.enqueue([](int answer) { return answer; }, 42);
// get result from future
std::cout << result.get() << std::endl;

CMake

Build options

  • THREADPOOL_LIBRARY_TYPE: Set the type of library to build.

    Supported options: OBJECT (default), STATIC, SHARED.

Import using find_package

Build and install ThreadPool somewhere on your system (note: OBJECT libraries cannot be installed).

find_package(ThreadsREQUIRED)
set(ThreadPool_DIR "</threadpool/install/dir>/share/cmake")
# You can actually skip the install step and use the build directory.set(ThreadPool_DIR "</threadpool/build/dir>")
find_package(ThreadsREQUIRED)
find_package(ThreadPool)
target_link_libraries(<your-target>PRIVATEThreadPool)

Import using FetchContent (CMake >= 3.11)

find_package(ThreadsREQUIRED)
FetchContent_Declare(ThreadPool
GIT_REPOSITORY git://github.com/jhasse/ThreadPool.git
)
# Optional# set(THREADPOOL_LIBRARY_TYPE SHARED)# If CMake >= 3.14FetchContent_MakeAvailable(ThreadPool)
# If CMake < 3.14FetchContent_GetProperties(ThreadPool)
if (NOT ThreadPool_POPULATED)
FetchContent_Populate(ThreadPool)
add_subdirectory("${ThreadPool_SOURCE_DIR}"${ThreadPool_BINARY_DIR})
endif()
target_link_libraries(<your-target>PRIVATEThreadPool)

About

A simple C++17 Thread Pool implementation

Resources

Stars

32 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages