-
Notifications
You must be signed in to change notification settings - Fork 11
Feature: set_thread_name #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: set_thread_name #107
Conversation
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
|
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 |
There was a problem hiding this 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,
nameis unused, which can trigger-Wunused-parameterin some builds. Consider adding a fallback#elsebranch.🧹 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`
|
GCOVR code coverage report https://107.capy.prtest3.cppalliance.org/gcovr/index.html Build time: 2026-01-23 21:41:25 UTC |
1056507 to
5f7bd72
Compare
Closes #85
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.