From dd669f40b98bb864bb9713673f0c38d946040591 Mon Sep 17 00:00:00 2001 From: ViniciusCestarii Date: Tue, 4 Aug 2026 11:59:11 -0300 Subject: [PATCH] util: set os-level thread names on Windows --- src/util/threadnames.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/threadnames.cpp b/src/util/threadnames.cpp index a9a3649b0b9..2c78fc24a85 100644 --- a/src/util/threadnames.cpp +++ b/src/util/threadnames.cpp @@ -18,6 +18,10 @@ #include #endif +#ifdef WIN32 +#include +#endif + //! Set the thread's name at the process level. Does not affect the //! internal name. static void SetThreadName(const char* name) @@ -29,6 +33,11 @@ static void SetThreadName(const char* name) pthread_set_name_np(pthread_self(), name); #elif defined(__APPLE__) pthread_setname_np(name); +#elif defined(WIN32) + // Thread names are ASCII-only, so widening each character is sufficient as + // a conversion to UTF-16. + const std::wstring wname{name, name + std::strlen(name)}; + ::SetThreadDescription(::GetCurrentThread(), wname.c_str()); #else // Prevent warnings for unused parameters... (void)name;