From 39aca6160918a6e9e7ecaf490bb9168a91589955 Mon Sep 17 00:00:00 2001 From: Steve Gerbino Date: Mon, 11 May 2026 18:37:19 +0200 Subject: [PATCH] feat(thread_pool): name worker threads tpool-svc-N Sets each worker's thread name via capy::set_current_thread_name so they show up in debuggers and system tools as tpool-svc-1, tpool-svc-2, etc. Format fits Linux's 15-char pthread name limit for indices up to 9999. --- include/boost/corosio/detail/thread_pool.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/boost/corosio/detail/thread_pool.hpp b/include/boost/corosio/detail/thread_pool.hpp index 1ba36a07..b5e382fc 100644 --- a/include/boost/corosio/detail/thread_pool.hpp +++ b/include/boost/corosio/detail/thread_pool.hpp @@ -13,8 +13,10 @@ #include #include #include +#include #include +#include #include #include #include @@ -81,7 +83,7 @@ class thread_pool final : public capy::execution_context::service std::vector threads_; bool shutdown_ = false; - void worker_loop(); + void worker_loop(unsigned index); public: using key_type = thread_pool; @@ -110,7 +112,7 @@ class thread_pool final : public capy::execution_context::service try { for (unsigned i = 0; i < num_threads; ++i) - threads_.emplace_back([this] { worker_loop(); }); + threads_.emplace_back([this, i] { worker_loop(i + 1); }); } catch (...) { @@ -145,8 +147,14 @@ class thread_pool final : public capy::execution_context::service }; inline void -thread_pool::worker_loop() +thread_pool::worker_loop(unsigned index) { + // Name format chosen to fit Linux's 15-char pthread limit: + // "tpool-svc-" (10) + up to 4 digit index leaves "tpool-svc-9999". + char name[16]; + std::snprintf(name, sizeof(name), "tpool-svc-%u", index); + capy::set_current_thread_name(name); + for (;;) { pool_work_item* w;