Skip to content

Conversation

@mvandeberg
Copy link
Contributor

@mvandeberg mvandeberg commented Jan 23, 2026

Closes #85

Summary by CodeRabbit

  • New Features

    • Thread pool constructor accepts an optional thread name prefix (default "capy-pool-") to customize worker names.
    • Worker threads are automatically named using the prefix+index for easier identification during debugging.
    • New public API to set the current thread’s name (cross‑platform, best‑effort).
  • Documentation

    • Notes added describing platform-specific name‑length limits and UTF‑8 considerations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Adds a portable thread-naming API (declaration + implementation) and integrates configurable per-worker naming into the thread_pool; each worker sets its name at startup using the provided prefix plus its index.

Changes

Cohort / File(s) Summary
Thread Naming API
include/boost/capy/detail/thread_name.hpp, src/detail/thread_name.cpp
Add exported declaration BOOST_CAPY_DECL void set_current_thread_name(char const* name) noexcept and platform-specific implementation. Windows uses SetThreadDescription (UTF‑8→UTF‑16 conversion), macOS/Linux/FreeBSD/NetBSD use pthread_setname_np with platform length limits; operations are best-effort and noexcept.
Thread Pool Integration
include/boost/capy/ex/thread_pool.hpp, src/ex/thread_pool.cpp
Add std::string_view thread_name_prefix parameter (default "capy-pool-") to thread_pool constructors/impl; store/truncate prefix (12 chars) and set each worker's name to prefix + index at thread start. Add includes: <string_view>, .../detail/thread_name.hpp, <cstdio> where used.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PoolCtor as "thread_pool::thread_pool(...)"
    participant Starter as "ensure_started"
    participant Worker as "WorkerThread[i]"
    participant NameAPI as "boost::capy::detail::set_current_thread_name"
    participant Platform as "OS-specific API"

    User->>PoolCtor: construct(num_threads, thread_name_prefix)
    PoolCtor->>Starter: ensure_started launches threads with indices
    Starter->>Worker: start thread i
    Worker->>NameAPI: set_current_thread_name(prefix + index)
    NameAPI->>Platform: call SetThreadDescription / pthread_setname_np
    Platform-->>NameAPI: (best-effort result ignored)
    Worker->>Worker: enter work loop
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 I hop and stitch a little name,

Prefix trimmed to win the game.
Each worker wakes with label light,
Hopping tidy through the night.
Debuggers smile at names in sight.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main feature: adding thread naming capability as described in the linked issue.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #85: portable thread naming with platform-specific APIs (Windows, Linux/FreeBSD, macOS), UTF-8 handling, name truncation, and integration with thread_pool.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing thread naming: new header with API declaration, platform-specific implementation, and thread_pool integration with thread_name_prefix parameter.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@mvandeberg mvandeberg changed the title Add thread naming support to thread_pool for debugging visibility Feature: thread_name Jan 23, 2026
@mvandeberg mvandeberg changed the title Feature: thread_name Feature: set_thread_name Jan 23, 2026
@cppalliance-bot
Copy link

cppalliance-bot commented Jan 23, 2026

An automated preview of the documentation is available at https://107.capy.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-01-23 22:08:13 UTC

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
include/boost/capy/ex/thread_pool.hpp (1)

14-20: Add the required file overview comment after the include block.

Right after the includes (Line 14–19), add the mandated /* */ high‑level overview of how this header works. As per coding guidelines, please add this section.

📄 Proposed overview block
 `#include` <boost/capy/ex/execution_context.hpp>
 `#include` <cstddef>
 `#include` <string_view>

+/*
+    Declares thread_pool and its executor, exposing the public API surface
+    for pooled coroutine execution.
+*/
 namespace boost {
src/ex/thread_pool.cpp (1)

11-20: Add the required file overview comment after the include block.

Right after the includes (Line 11–19), add the mandated /* */ high‑level overview of how this implementation works. As per coding guidelines, please add this section.

📄 Proposed overview block
 `#include` <stop_token>
 `#include` <thread>
 `#include` <vector>

+/*
+    Implements thread_pool internals: work queue, worker lifecycle, and
+    executor posting behavior.
+*/
 namespace boost {
🤖 Fix all issues with AI agents
In `@include/boost/capy/detail/thread_name.hpp`:
- Around line 26-31: Move or insert the required file overview comment
immediately after the include block in include/boost/capy/detail/thread_name.hpp
so the header-level summary appears before the namespace declarations; update
the comment to be a short file overview placed between the `#include`
<boost/capy/detail/config.hpp> and the opening namespace boost::capy::detail {
to follow the coding guideline.

In `@src/detail/thread_name.cpp`:
- Around line 10-33: Add a C-style file overview comment block (/* ... */)
immediately after the include block and before the namespace boost::capy::detail
opening in src/detail/thread_name.cpp; the comment should briefly state the
purpose (setting/reading thread names cross-platform), outline the
platform-specific approach used for Windows
(SetThreadDescription/GetThreadDescription or Win32 API), macOS
(pthread_setname_np/pthread_getname_np) and Linux/FreeBSD/NetBSD
(pthread_setname_np/pthread_getname_np with length caveats), and note any
important limits or fallback behavior so readers of thread_name.cpp can quickly
understand the implementation.
- Around line 41-49: The current thread_name.cpp code silently fails when UTF-8
-> wide conversion needs more than the fixed wchar_t wname[128] buffer; call
MultiByteToWideChar first with output buffer=NULL to get required wide length,
then if required>128 either (a) truncate the conversion to 127 wide characters
and null-terminate so long names are truncated (matching other platforms) or (b)
allocate a std::wstring of the required size and perform the conversion into it
(remember to `#include` <string>) before calling
SetThreadDescription(GetCurrentThread(), ...); ensure you still treat
SetThreadDescription as best-effort and keep the null-terminated wide string
when invoking it.
🧹 Nitpick comments (1)
src/detail/thread_name.cpp (1)

59-67: Silence unused-parameter warnings on unsupported platforms.

If none of the platform macros match, name is unused, which can trigger -Wunused-parameter in some builds. Consider adding a fallback #else branch.

🧹 Suggested change
 `#elif` defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
     // pthread_setname_np has 16 char limit (15 + null terminator)
     char truncated[16];
     std::strncpy(truncated, name, 15);
     truncated[15] = '\0';

     // Ignore return value: thread naming is best-effort for debugging.
     (void)pthread_setname_np(pthread_self(), truncated);
+#else
+    (void)name;
 `#endif`

@cppalliance-bot
Copy link

cppalliance-bot commented Jan 23, 2026

GCOVR code coverage report https://107.capy.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://107.capy.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report (in development) https://107.capy.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-01-23 21:41:25 UTC

@mvandeberg mvandeberg force-pushed the feature/set_thread_name branch from 1056507 to 5f7bd72 Compare January 23, 2026 21:05
@mvandeberg mvandeberg merged commit c5cfa8a into cppalliance:develop Jan 23, 2026
15 checks passed
@mvandeberg mvandeberg deleted the feature/set_thread_name branch January 23, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

set thread name

2 participants