From a9d0fb9647d9215039add4e78a86e100d7bc587d Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Fri, 27 Feb 2026 15:47:11 -0500 Subject: [PATCH 1/5] chore: add clangd config --- .clangd | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .clangd diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..2b4270d --- /dev/null +++ b/.clangd @@ -0,0 +1,5 @@ +Diagnostics: + MissingIncludes: Strict + UnusedIncludes: Strict +CompileFlags: + CompilationDatabase: ./out/build/x64-debug-clang From 5681cdb59eb7c2bc45ed794b9eaa025a54aedb0f Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Fri, 27 Feb 2026 15:47:30 -0500 Subject: [PATCH 2/5] chore: turn on compile commands export on windows --- CMakePresets.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 6db92e1..609f2bf 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -27,7 +27,8 @@ "binaryDir": "${sourceDir}/out/build/${presetName}", "installDir": "${sourceDir}/out/install/${presetName}", "cacheVariables": { - "CMAKE_CXX_COMPILER": "cl" + "CMAKE_CXX_COMPILER": "cl", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" }, "condition": { "type": "equals", @@ -167,4 +168,4 @@ } } ] -} \ No newline at end of file +} From 1b7af057661bee8b173ac9d34fb353770c456261 Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Fri, 27 Feb 2026 15:47:43 -0500 Subject: [PATCH 3/5] chore: add missing includes --- benchmark/source/matrix_multiplication.cpp | 8 ++++ benchmark/source/thread_pool_scaling.cpp | 1 + include/thread_pool/thread_pool.h | 48 +++++++++++----------- include/thread_pool/thread_safe_queue.h | 1 + 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/benchmark/source/matrix_multiplication.cpp b/benchmark/source/matrix_multiplication.cpp index bcfa906..2945169 100644 --- a/benchmark/source/matrix_multiplication.cpp +++ b/benchmark/source/matrix_multiplication.cpp @@ -3,11 +3,19 @@ #include #include +#include #include +#include #include +#include +#include #include #include +#include #include +#include +#include +#include #include "utilities.h" diff --git a/benchmark/source/thread_pool_scaling.cpp b/benchmark/source/thread_pool_scaling.cpp index 15ba84a..798b714 100644 --- a/benchmark/source/thread_pool_scaling.cpp +++ b/benchmark/source/thread_pool_scaling.cpp @@ -4,6 +4,7 @@ #include #include +#include #include inline void thread_task() { diff --git a/include/thread_pool/thread_pool.h b/include/thread_pool/thread_pool.h index 4b97ec5..7a4c276 100644 --- a/include/thread_pool/thread_pool.h +++ b/include/thread_pool/thread_pool.h @@ -2,13 +2,15 @@ #include #include +#include #include #include #include -#include #include #include +#include // std::ignore #include + #ifdef __has_include # if __has_include() # include @@ -37,7 +39,7 @@ namespace dp { requires std::invocable && std::is_same_v> explicit thread_pool( - const unsigned int &number_of_threads = std::thread::hardware_concurrency(), + const unsigned int& number_of_threads = std::thread::hardware_concurrency(), InitializationFunction init = [](std::size_t) {}) : tasks_(number_of_threads) { std::size_t current_id = 0; @@ -45,7 +47,7 @@ namespace dp { priority_queue_.push_back(size_t(current_id)); try { threads_.emplace_back([&, id = current_id, - init](const std::stop_token &stop_tok) { + init](const std::stop_token& stop_tok) { // invoke the init function on the thread try { std::invoke(init, id); @@ -124,8 +126,8 @@ namespace dp { } /// thread pool is non-copyable - thread_pool(const thread_pool &) = delete; - thread_pool &operator=(const thread_pool &) = delete; + thread_pool(const thread_pool&) = delete; + thread_pool& operator=(const thread_pool&) = delete; /** * @brief Enqueue a task into the thread pool that returns a result. @@ -138,7 +140,7 @@ namespace dp { * @return A std::future that can be used to retrieve the returned value. */ template > + typename ReturnType = std::invoke_result_t> requires std::invocable [[nodiscard]] std::future enqueue(Function f, Args... args) { #ifdef __cpp_lib_move_only_function @@ -205,22 +207,22 @@ namespace dp { */ template requires std::invocable - void enqueue_detach(Function &&func, Args &&...args) { - enqueue_task(std::move([f = std::forward(func), - ... largs = - std::forward(args)]() mutable -> decltype(auto) { - // suppress exceptions - try { - if constexpr (std::is_same_v>) { - std::invoke(f, largs...); - } else { - // the function returns an argument, but can be ignored - std::ignore = std::invoke(f, largs...); + void enqueue_detach(Function&& func, Args&&... args) { + enqueue_task( + std::move([f = std::forward(func), + ... largs = std::forward(args)]() mutable -> decltype(auto) { + // suppress exceptions + try { + if constexpr (std::is_same_v>) { + std::invoke(f, largs...); + } else { + // the function returns an argument, but can be ignored + std::ignore = std::invoke(f, largs...); + } + } catch (...) { } - } catch (...) { - } - })); + })); } /** @@ -251,7 +253,7 @@ namespace dp { */ size_t clear_tasks() { size_t removed_task_count{0}; - for (auto &task_list : tasks_) { + for (auto& task_list : tasks_) { removed_task_count += task_list.tasks.clear(); } in_flight_tasks_.fetch_sub(removed_task_count, std::memory_order_release); @@ -262,7 +264,7 @@ namespace dp { private: template - void enqueue_task(Function &&f) { + void enqueue_task(Function&& f) { auto i_opt = priority_queue_.copy_front_and_rotate_to_back(); if (!i_opt.has_value()) { // would only be a problem if there are zero threads diff --git a/include/thread_pool/thread_safe_queue.h b/include/thread_pool/thread_safe_queue.h index ac75397..8e5141b 100644 --- a/include/thread_pool/thread_safe_queue.h +++ b/include/thread_pool/thread_safe_queue.h @@ -5,6 +5,7 @@ #include #include #include +#include // std::ignore namespace dp { /** From 0fa2026f88608dce9f73eff825089a2171301d3b Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Wed, 4 Mar 2026 19:40:57 -0500 Subject: [PATCH 4/5] chore: update min cmake version to 3.25 --- CMakeLists.txt | 2 +- benchmark/CMakeLists.txt | 2 +- documentation/CMakeLists.txt | 2 +- examples/mandelbrot/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b283a5..d8e3328 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19 FATAL_ERROR) +cmake_minimum_required(VERSION 3.25 FATAL_ERROR) # ---- Project ---- diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index a23955f..1cc6ad3 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19 FATAL_ERROR) +cmake_minimum_required(VERSION 3.25 FATAL_ERROR) project(thread-pool-benchmarks LANGUAGES CXX) diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index d743bb5..fe21f01 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19 FATAL_ERROR) +cmake_minimum_required(VERSION 3.25 FATAL_ERROR) project(ThreadPoolDocs) diff --git a/examples/mandelbrot/CMakeLists.txt b/examples/mandelbrot/CMakeLists.txt index dae8396..55e9122 100644 --- a/examples/mandelbrot/CMakeLists.txt +++ b/examples/mandelbrot/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19 FATAL_ERROR) +cmake_minimum_required(VERSION 3.25 FATAL_ERROR) project(Mandelbrot LANGUAGES CXX) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1fe084b..4258fbd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19 FATAL_ERROR) +cmake_minimum_required(VERSION 3.25 FATAL_ERROR) project(thread-pool-tests LANGUAGES CXX) From a9ea96cd4148246b1579d76347604fda9cdccfc4 Mon Sep 17 00:00:00 2001 From: Paul Tsouchlos Date: Wed, 4 Mar 2026 19:41:39 -0500 Subject: [PATCH 5/5] chore: auto format code --- CMakePresets.json | 9 ++++++--- examples/mandelbrot/include/fractal.h | 6 +++--- examples/mandelbrot/source/main.cpp | 6 +++--- include/thread_pool/thread_pool.h | 2 +- include/thread_pool/thread_safe_queue.h | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 609f2bf..93a72a3 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -106,7 +106,8 @@ { "name": "x64-debug", "displayName": "x64 Debug", - "description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)", + "description": + "Target Windows (64-bit) with the Visual Studio development environment. (Debug)", "inherits": "windows-base", "architecture": { "value": "x64", @@ -140,7 +141,8 @@ { "name": "x64-release", "displayName": "x64 Release", - "description": "Target Windows (64-bit) with the Visual Studio development environment. (Release)", + "description": + "Target Windows (64-bit) with the Visual Studio development environment. (Release)", "inherits": "x64-debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" @@ -149,7 +151,8 @@ { "name": "x64-release-with-debug", "displayName": "x64 Release w/Debug", - "description": "Target Windows (64-bit) with the Visual Studio development environment. (RelWithDebInfo)", + "description": + "Target Windows (64-bit) with the Visual Studio development environment. (RelWithDebInfo)", "inherits": "x64-debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" diff --git a/examples/mandelbrot/include/fractal.h b/examples/mandelbrot/include/fractal.h index 9cd21ba..989ff83 100644 --- a/examples/mandelbrot/include/fractal.h +++ b/examples/mandelbrot/include/fractal.h @@ -33,7 +33,7 @@ struct fractal_window { /// @brief Performs smooth polynomial fitting to the given value. rgb get_rgb_smooth(int n, int iter_max); -void save_ppm(const unsigned int &width, const unsigned int &height, std::span colors, +void save_ppm(const unsigned int& width, const unsigned int& height, std::span colors, std::string_view file_name); /** * @brief Convert a pixel coordinate to the complex domain @@ -41,7 +41,7 @@ void save_ppm(const unsigned int &width, const unsigned int &height, std::span &scr, const fractal_window &fr, complex c); +complex scale(const fractal_window& scr, const fractal_window& fr, complex c); /** * @brief Check if a point is in the set or escapes to infinity, return the number if iterations @@ -49,7 +49,7 @@ complex scale(const fractal_window &scr, const fractal_window &fr, * @param iter_max Max number of iterations * @param func The complex function used for the fractal. */ -int escape(complex c, int iter_max, const std::function &func); +int escape(complex c, int iter_max, const std::function& func); /** * @brief Calculate a single fractal row and returns it's color values. diff --git a/examples/mandelbrot/source/main.cpp b/examples/mandelbrot/source/main.cpp index 2e7f09c..059b6f8 100644 --- a/examples/mandelbrot/source/main.cpp +++ b/examples/mandelbrot/source/main.cpp @@ -41,7 +41,7 @@ void mandelbrot_threadpool(int image_width, int image_height, int max_iterations colors.reserve(source.size()); // copy data to output vector - for (auto &future : futures) { + for (auto& future : futures) { auto data = future.get(); colors.insert(colors.end(), data.begin(), data.end()); } @@ -56,7 +56,7 @@ void mandelbrot_threadpool(int image_width, int image_height, int max_iterations save_ppm(source.width(), source.height(), colors, output_file_name); } -auto main(int argc, char **argv) -> int { +auto main(int argc, char** argv) -> int { cxxopts::Options options(*argv, "Generate a mandelbrot ppm image using a thread pool!"); int image_size; @@ -83,7 +83,7 @@ auto main(int argc, char **argv) -> int { mandelbrot_threadpool(image_size, image_size, max_iterations, output_file_name); - } catch (const cxxopts::exceptions::exception &e) { + } catch (const cxxopts::exceptions::exception& e) { std::cout << "error parsing options: " << e.what() << std::endl; exit(1); } diff --git a/include/thread_pool/thread_pool.h b/include/thread_pool/thread_pool.h index 7a4c276..5817c44 100644 --- a/include/thread_pool/thread_pool.h +++ b/include/thread_pool/thread_pool.h @@ -8,7 +8,7 @@ #include #include #include -#include // std::ignore +#include // std::ignore #include #ifdef __has_include diff --git a/include/thread_pool/thread_safe_queue.h b/include/thread_pool/thread_safe_queue.h index 8e5141b..8ed0a00 100644 --- a/include/thread_pool/thread_safe_queue.h +++ b/include/thread_pool/thread_safe_queue.h @@ -5,7 +5,7 @@ #include #include #include -#include // std::ignore +#include // std::ignore namespace dp { /**