feat: Add new thread_pool component built on top of Task#673
Conversation
|
✅Static analysis result - no issues found! ✅ |
There was a problem hiding this comment.
Pull request overview
Adds a new thread_pool component to ESPP, providing an espp::ThreadPool API backed by espp::Task workers, plus an ESP-IDF example project demonstrating job submission and basic stats reporting.
Changes:
- Introduces
espp::ThreadPoolimplementation with a configurable worker count, optional bounded queue, and submission/statistics APIs. - Adds an ESP-IDF example (
components/thread_pool/example) showing how to run multiple jobs and wait for completion. - Adds component packaging metadata (
idf_component.yml) and CMake integration for the new component.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| components/thread_pool/src/thread_pool.cpp | Implements worker lifecycle, queueing, and worker callback behavior. |
| components/thread_pool/include/thread_pool.hpp | Public API, configuration, and documentation/comments for ThreadPool. |
| components/thread_pool/README.md | Component-level README and feature list. |
| components/thread_pool/idf_component.yml | Component Manager manifest (metadata, docs URL, dependencies). |
| components/thread_pool/CMakeLists.txt | Registers the component with ESP-IDF build system. |
| components/thread_pool/example/CMakeLists.txt | Example project CMake configuration and component selection. |
| components/thread_pool/example/main/CMakeLists.txt | Registers the example’s main component. |
| components/thread_pool/example/main/thread_pool_example.cpp | Example app demonstrating pool usage and completion waiting. |
| components/thread_pool/example/README.md | Example build/run instructions. |
| components/thread_pool/example/sdkconfig.defaults | Enables C++ exceptions for the example build. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (2)
components/thread_pool/README.md:12
- README claims stop "drains queued jobs", but ThreadPool::stop() explicitly warns that queued jobs may not be executed (and the current implementation can leave queued jobs unprocessed). Please update this feature bullet to match the actual stop semantics so users aren’t misled.
- Graceful stop (stops workers; queued jobs may not be executed)
components/thread_pool/idf_component.yml:8
documentationpoints tocore/thread_pool.html, but there are no correspondingdoc/en/**pages and nodoc/DoxyfileINPUT/EXAMPLE_PATH entries for this new component. This will produce a broken documentation link and omit the API/example from the published docs; please add the required doc pages and Doxyfile entries (kept in alphabetical order) so the link resolves.
documentation: "https://esp-cpp.github.io/espp/core/thread_pool.html"
| project(thread_pool_example) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 20) |
| idf_component_register( | ||
| INCLUDE_DIRS "include" | ||
| SRC_DIRS "src" | ||
| REQUIRES base_component task) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.
Comments suppressed due to low confidence (1)
doc/en/core/thread_pool_example.md:3
- The include path looks incorrect relative to
doc/en/core/thread_pool_example.md.../../components/...resolves underdoc/components/..., not<repo_root>/components/.... Update the include path (likely to../../../components/thread_pool/example/README.md) so docs builds can actually find the example README.
thread_pool component built on top of Task
There was a problem hiding this comment.
@guo-max can you please update the example to exercise / demonstrate all of the public APIs of the thread pool class?
| /// @brief Snapshot of pool activity counters. | ||
| struct Stats { | ||
| std::uint64_t submitted = 0; ///< Total jobs accepted into the queue. | ||
| std::uint64_t executed = 0; ///< Total jobs successfully executed. | ||
| std::uint64_t rejected = 0; ///< Total jobs rejected (invalid job, stopped/stopping, or queue full). | ||
| }; |
There was a problem hiding this comment.
Can you please add format helpers header for this struct so that it can be simply passed to fmt via {} (optionally with some format args to control short versus verbose printing)? There are other examples of *_format_helpers.hpp within espp that you can use for reference
Description
add Thread_pool component
Motivation and Context
A thread pool that dispatches submitted jobs to a fixed set of worker threads.
How has this been tested?
an example is added and tested.
The example was tested on an esp32 board. it use a thread_pool with 2 works and finished 8 jobs.
Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.Hardware