Skip to content

feat: Add new thread_pool component built on top of Task#673

Open
guo-max wants to merge 14 commits into
mainfrom
feat/thread_pool
Open

feat: Add new thread_pool component built on top of Task#673
guo-max wants to merge 14 commits into
mainfrom
feat/thread_pool

Conversation

@guo-max

@guo-max guo-max commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

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):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

Hardware

  • I have updated the design files (schematic, board, libraries).
  • I have attached the PDFs of the SCH / BRD to this PR
  • I have updated the design output (GERBER, BOM) files.

Copilot AI review requested due to automatic review settings July 22, 2026 14:14
@github-actions

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::ThreadPool implementation 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.

Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/include/thread_pool.hpp
Comment thread components/thread_pool/include/thread_pool.hpp Outdated
Comment thread components/thread_pool/idf_component.yml
Comment thread components/thread_pool/README.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 22, 2026 15:18
guo-max and others added 2 commits July 22, 2026 10:19
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • documentation points to core/thread_pool.html, but there are no corresponding doc/en/** pages and no doc/Doxyfile INPUT/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"

Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment on lines +20 to +22
project(thread_pool_example)

set(CMAKE_CXX_STANDARD 20)
Comment on lines +1 to +4
idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src"
REQUIRES base_component task)
Copilot AI review requested due to automatic review settings July 22, 2026 15:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/include/thread_pool.hpp Outdated
Comment thread components/thread_pool/include/thread_pool.hpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/example/main/thread_pool_example.cpp
Copilot AI review requested due to automatic review settings July 22, 2026 15:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 16:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/idf_component.yml
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 22, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.

Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/include/thread_pool.hpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/idf_component.yml
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 16:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 under doc/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.

Comment thread components/thread_pool/example/main/thread_pool_example.cpp Outdated
Comment thread components/thread_pool/example/main/thread_pool_example.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Comment thread components/thread_pool/example/main/thread_pool_example.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp
Copilot AI review requested due to automatic review settings July 22, 2026 18:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread doc/en/core/thread_pool.rst Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 18:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread components/thread_pool/src/thread_pool.cpp Outdated
Comment thread doc/en/core/thread_pool.rst Outdated
Comment thread components/thread_pool/idf_component.yml
Comment thread components/thread_pool/example/CMakeLists.txt Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 19:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/include/thread_pool.hpp
Comment thread components/thread_pool/src/thread_pool.cpp
Comment thread components/thread_pool/idf_component.yml
@finger563 finger563 changed the title Feat/thread pool feat: Add new thread_pool component built on top of Task Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guo-max can you please update the example to exercise / demonstrate all of the public APIs of the thread pool class?

Comment on lines +30 to +35
/// @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).
};

@finger563 finger563 Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request thread pool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants