From 85d54c53de2e625192ded6731e371b586c4fd677 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sun, 20 Mar 2022 16:12:21 +0000 Subject: [PATCH] Feature: Support pthread_setname_np() --- thread/thread.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/thread/thread.c b/thread/thread.c index e059edf..c6c6505 100644 --- a/thread/thread.c +++ b/thread/thread.c @@ -314,6 +314,14 @@ thread_type *thread_create_c(const char *name, void *(*start_routine)(void *), if (pthread_create (&thread->sys_thread, &attr, _start_routine, start) == 0) { pthread_attr_destroy (&attr); +#ifdef HAVE_PTHREAD_SETNAME_NP + if (pthread_setname_np(thread->sys_thread, name) != 0) { + /* If the call above did not work it was likely due to name limit restrictions. + * In that case we retry with a fixed name so we do not inherit our parent's name. + */ + pthread_setname_np(thread->sys_thread, "Worker"); + } +#endif return thread; } else