LibThreading: Set system threads' names based on Thread::thread_name()

This commit is contained in:
Zaggy1024
2026-01-23 14:55:51 -06:00
committed by Gregory Bertilson
parent c4e95079e1
commit 3cb39baa44
Notes: github-actions[bot] 2026-02-06 11:03:34 +00:00

View File

@@ -77,6 +77,20 @@ void Thread::start()
[](void* arg) -> void* {
auto self = adopt_ref(*static_cast<Thread*>(arg));
{
// pthread_setname_np expects a 16-byte or shorter null-terminated C string.
auto thread_name = self->thread_name().substring(0, min(self->thread_name().length(), 15));
#if defined(AK_OS_MACOS)
pthread_setname_np(thread_name.characters());
#elif defined(AK_OS_OPENBSD)
pthread_set_name_np(pthread_self(), thread_name.characters());
#elif defined(AK_OS_NETBSD)
pthread_setname_np(pthread_self(), "%s", const_cast<char*>(thread_name.characters()));
#else
pthread_setname_np(pthread_self(), thread_name.characters());
#endif
}
auto exit_code = self->m_action();
auto expected = Threading::ThreadState::Running;