PTHREAD_ATTR_GET_NP(3)
π PTHREAD_ATTR_GET_NP(3) β the girlies' guide to snatching another thread's attributes
okay so welcome to PTHREAD_ATTR_GET_NP(3), bestie π
this is a page from the Library Functions Manual, and it's about grabbing the attributes of a thread that's already out here living its life. no cap, it's a real one.
β¨ NAME β¨
pthread_attr_get_np β get attributes of an existing thread π«Ά
π LIBRARY π
POSIX Threads Library (libpthread, -lpthread) β yes you gotta link it, don't forget, iykyk.
πΈ SYNOPSIS πΈ
#include <pthread_np.h>
int
pthread_attr_get_np(pthread_t pid, pthread_attr_t *dst);
π DESCRIPTION π
so the way that pthread_attr_get_np() works is: it retrieves the attributes of the thread you point at, and dumps them into a pthread_attr_t structure you already have sitting there. it does not make you a new one, it fills in yours. main character energy fr.
the values you get are the current ones for the target thread β like, live, right now, not some stale snapshot from when it was born. with one tiny exception, bestie: the stack top address if it's not properly aligned for the architecture. in that case its value has been adjusted internally before use, so that's just how it is. β¨
and listen β argument dst must be a pointer to a valid attributes object. valid means it was initialized at some point by pthread_attr_init(3) and has not been destroyed since then. that's the vibe check, don't skip it π
after a successful call to pthread_attr_get_np(), you can pull out the individual attributes' values as usual via the corresponding accessor functions, all documented in pthread_attr(3). slay.
after a failed call to pthread_attr_get_np(), the object pointed to by dst is left unmodified, and you can keep using it as if the failed call never happened. like it literally never met you. iconic behaviour honestly.
β RETURN VALUES β
if everything's good, pthread_attr_get_np() returns 0. π
otherwise, an error number is returned to indicate the error. (note: it returns the error number, it doesn't set errno β different thing, don't get it twisted π)
π EXAMPLES π
this function retrieves the stack size of the thread specified by the pid argument:
size_t
my_thread_stack_size(pthread_t tid)
{
pthread_attr_t attr;
size_t size;
pthread_attr_init(&attr);
pthread_attr_get_np(tid, &attr);
pthread_attr_getstacksize(&attr, &size);
pthread_attr_destroy(&attr);
return (size);
}
init, get, getstacksize, destroy, return. the whole little routine, and honestly? it ate. π₯
π ERRORS π
the pthread_attr_get_np() function will fail if:
[EINVAL]β one of the arguments has an invalid value. π©[ESRCH]β no thread could be found corresponding to that specified by the given thread ID. she's not here, bestie π[ENOMEM]β there was not enough memory to allocate additional storage needed by the attributes object's implementation. the malloc said no π
π¦ SEE ALSO π¦
literally the whole squad, go read them:
pthread_attr(3)pthread_attr_destroy(3)pthread_attr_getdetachstate(3)pthread_attr_getinheritsched(3)pthread_attr_getschedparam(3)pthread_attr_getschedpolicy(3)pthread_attr_getscope(3)pthread_attr_getstack(3)pthread_attr_getstackaddr(3)pthread_attr_getstacksize(3)pthread_attr_init(3)pthread_np(3)
π AUTHORS π
the pthread_attr_get_np() function and this manual page were written by Alexey Zelkin <phantom@FreeBSD.org>, and the latter was revised by Olivier Certner <olce@FreeBSD.org>. absolute legends, we stan π«Ά
okay that's the whole page, bestie, you're officially educated π
this cutie pie was brought to you by Debian, dated January 5, 2024, and yes it's still PTHREAD_ATTR_GET_NP(3) β same page, same facts, way more personality. periodt. πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2002,2003 Alexey Zelkin <phantom@FreeBSD.org>
- Copyright (c) 2024 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms