Skip to content

Commit 8bd2adf

Browse files
author
Rishabh Rohil
committed
Initial release: Modern C++17 Thread Pool Library
Features: - Header-only library with zero dependencies - Configurable worker thread count - Typed futures for return values - Work-stealing scheduler for load balancing - Priority task scheduling - Thread-safe task queue with condition variables - Graceful shutdown with wait/cancel options - Pool statistics and metrics - Comprehensive test suite - Performance benchmarks - Example applications (parallel sort, web crawler)
0 parents  commit 8bd2adf

File tree

16 files changed

+2210
-0
lines changed

16 files changed

+2210
-0
lines changed

.github/workflows/ci.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-linux:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
compiler: [gcc, clang]
15+
build_type: [Debug, Release]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install dependencies
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y cmake ninja-build
24+
25+
- name: Configure CMake
26+
run: |
27+
cmake -B build -G Ninja \
28+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
29+
-DCMAKE_CXX_COMPILER=${{ matrix.compiler == 'gcc' && 'g++' || 'clang++' }}
30+
31+
- name: Build
32+
run: cmake --build build
33+
34+
- name: Test
35+
working-directory: build
36+
run: ctest --output-on-failure
37+
38+
build-macos:
39+
runs-on: macos-latest
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Configure CMake
45+
run: cmake -B build -DCMAKE_BUILD_TYPE=Release
46+
47+
- name: Build
48+
run: cmake --build build
49+
50+
- name: Test
51+
working-directory: build
52+
run: ctest --output-on-failure
53+
54+
build-windows:
55+
runs-on: windows-latest
56+
57+
steps:
58+
- uses: actions/checkout@v4
59+
60+
- name: Configure CMake
61+
run: cmake -B build
62+
63+
- name: Build
64+
run: cmake --build build --config Release
65+
66+
- name: Test
67+
working-directory: build
68+
run: ctest -C Release --output-on-failure

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Build directories
2+
build/
3+
cmake-build-*/
4+
out/
5+
6+
# IDE files
7+
.idea/
8+
.vscode/
9+
*.swp
10+
*.swo
11+
*~
12+
13+
# Compiled files
14+
*.o
15+
*.obj
16+
*.exe
17+
*.out
18+
*.app
19+
20+
# CMake generated
21+
CMakeCache.txt
22+
CMakeFiles/
23+
cmake_install.cmake
24+
Makefile
25+
compile_commands.json
26+
27+
# Testing
28+
Testing/
29+
CTestTestfile.cmake
30+
31+
# Package files
32+
*.tar.gz
33+
*.zip
34+
35+
# macOS
36+
.DS_Store
37+
38+
# Windows
39+
Thumbs.db

CMakeLists.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(cpp-threadpool
3+
VERSION 1.0.0
4+
DESCRIPTION "Modern C++17 thread pool library"
5+
LANGUAGES CXX
6+
)
7+
8+
# C++17 required
9+
set(CMAKE_CXX_STANDARD 17)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
set(CMAKE_CXX_EXTENSIONS OFF)
12+
13+
# Options
14+
option(THREADPOOL_BUILD_TESTS "Build unit tests" ON)
15+
option(THREADPOOL_BUILD_EXAMPLES "Build examples" ON)
16+
option(THREADPOOL_BUILD_BENCHMARKS "Build benchmarks" ON)
17+
18+
# Header-only library target
19+
add_library(threadpool INTERFACE)
20+
add_library(tp::threadpool ALIAS threadpool)
21+
22+
target_include_directories(threadpool INTERFACE
23+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
24+
$<INSTALL_INTERFACE:include>
25+
)
26+
27+
target_compile_features(threadpool INTERFACE cxx_std_17)
28+
29+
# Find threads
30+
find_package(Threads REQUIRED)
31+
target_link_libraries(threadpool INTERFACE Threads::Threads)
32+
33+
# Tests
34+
if(THREADPOOL_BUILD_TESTS)
35+
enable_testing()
36+
add_subdirectory(tests)
37+
endif()
38+
39+
# Examples
40+
if(THREADPOOL_BUILD_EXAMPLES)
41+
add_subdirectory(examples)
42+
endif()
43+
44+
# Benchmarks
45+
if(THREADPOOL_BUILD_BENCHMARKS)
46+
add_subdirectory(benchmarks)
47+
endif()
48+
49+
# Installation
50+
include(GNUInstallDirs)
51+
install(TARGETS threadpool
52+
EXPORT threadpool-targets
53+
)
54+
55+
install(DIRECTORY include/threadpool
56+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
57+
)
58+
59+
install(EXPORT threadpool-targets
60+
FILE threadpool-config.cmake
61+
NAMESPACE tp::
62+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/threadpool
63+
)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Rishabh Rohil
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)