PTHREAD_SET_NAME_NP(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… PTHREAD_SET_NAME_NP(3) β€” the Library Functions Manual page, but make it cute

okay so bestie, we're in section 3 of the manual (that's the library functions one, iykyk) and today's main character is naming your threads. yes, your threads. they deserve names too πŸŽ€


✨ NAME ✨

pthread_get_name_np, pthread_getname_np, pthread_set_name_np, pthread_setname_np β€” the whole "set and retrieve the thread name" situation, fr fr


πŸ“š LIBRARY πŸ“š

POSIX Threads Library β€” that's libpthread, and you link it with -lpthread. slay.


🌸 SYNOPSIS 🌸

#include <pthread_np.h>

void
pthread_get_name_np(pthread_t thread, char *name, size_t len);

int
pthread_getname_np(pthread_t thread, char *name, size_t len);

void
pthread_set_name_np(pthread_t thread, const char *name);

int
pthread_setname_np(pthread_t thread, const char *name);

look at all four of them. iconic lineup honestly πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

so pthread_set_name_np() and pthread_setname_np() both take the name you give them, make a copy of it, and stick that copy onto the thread you passed in. no cap, that's the whole vibe. 🏷️

meanwhile pthread_get_name_np() and pthread_getname_np() are the reverse β€” they go fetch the name that's associated with thread and hand it back to you. and here's the little detail you need to know: if pthread_set_name_np() was never called for that thread before, the buffer that name points to will just be empty. not stale, not guessy β€” empty. periodt. πŸ«™


🚨 ERRORS 🚨

pthread_getname_np and pthread_setname_np will fail β€” like actually return an error to you β€” if:

  • [ESRCH] β€” no thread could be found in the current process that corresponds to that thread ID thread you handed over. it's giving "who? never met her." πŸ’€
and now for the plot twist: because pthread_get_name_np and pthread_set_name_np are debugging-type functions, all errors that may appear inside them are silently ignored. not reported, not returned, not a peep. so don't expect them to tell you when something's off πŸ™ˆ

πŸ‘€ SEE ALSO πŸ‘€

go read those too, bestie, cross-referencing is self care πŸ’œ


🌈 STANDARDS 🌈

pthread_set_name_np() and pthread_get_name_np() are non-standard extensions. and pthread_setname_np() and pthread_getname_np()? also non-standard β€” but a larger number of operating systems implement them, which lowkey means they're in fact more portable. the way that worked out 😭✨


πŸ–‹οΈ AUTHORS πŸ–‹οΈ

this manual page was written by Alexey Zelkin <phantom@FreeBSD.org> and Yuri Pankov <yuripv@yuripv.net>. thank you for your service 🫢


and that's the tea, babes β€” this page came from Debian, dated October 12, 2021, and it's PTHREAD_SET_NAME_NP(3) forever and always. go name a thread after your bestie, she'll be so honored πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from