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;