PTHREAD_ATTR_GETSTACKADDR(3)
π pthread_attr_setstackaddr, pthread_attr_getstackaddr π
okay bestie, sit down, we need to talk. this is a libpthread page (that's the POSIX threads library, you link it with -lpthread) and it's about two functions that set and get the stack address attribute in a thread attributes object. β¨
but like. they're obsolete. dead. ghosted by POSIX. we'll get there. πͺ¦
β¨ NAME β¨
pthread_attr_setstackaddr, pthread_attr_getstackaddr β set/get stack address attribute in thread attributes object
π LIBRARY π
POSIX threads library (libpthread, -lpthread)
π SYNOPSIS π
#include <pthread.h>
[[deprecated]]
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
[[deprecated]]
int pthread_attr_getstackaddr(const pthread_attr_t *restrict attr,
void **restrict stackaddr);
see that [[deprecated]]? the compiler is literally side-eyeing you. π
πΈ DESCRIPTION πΈ
okay so. these functions are obsolete: do not use them. like, not "eh maybe don't", but do not. instead you want pthread_attr_setstack(3) and pthread_attr_getstack(3). they're the glow-up versions. π
pthread_attr_setstackaddr() sets the stack address attribute of the thread attributes object pointed to by attr to whatever value you passed in stackaddr. that attribute is basically saying "hey, the stack a thread created with this attributes object should use lives here".
stackaddr should point to a buffer of at least PTHREAD_STACK_MIN bytes that the caller allocated. no, the library is not doing it for you, you're the main character here. and the pages of that buffer you allocated need to be both readable and writable. both. no skipping. π
pthread_attr_getstackaddr() returns the stack address attribute of the thread attributes object pointed to by attr, and it drops it into the buffer pointed to by stackaddr. surprise, it's the value you set. π
π₯ RETURN VALUE π₯
slay = 0. on success, these functions return 0. if something goes wrong, they return a nonzero error number. that's it, that's the whole vibe.
π ERRORS π
No errors are defined. but the manpage is like "bestie please still handle a possible error return" β applications should nevertheless handle a possible error return. so. yeah. defensive coding, periodt. π‘οΈ
π ATTRIBUTES π
for an explanation of the terms used in this section, go peek at attributes(7).
- Interface:
pthread_attr_setstackaddr(),pthread_attr_getstackaddr() - Attribute: Thread safety
- Value:
MT-Safe
so they're thread-safe, which is genuinely iconic of them, considering everything else going on. π«Ά
π STANDARDS π
None. nope. not a single one. they're not standardized by anyone. π
π¦ HISTORY π¦
- came into the world in glibc 2.1
- marked obsolete in
POSIX.1-2001 - straight up removed in
POSIX.1-2008
a whole arc. a rise and a fall. π
β NOTES β
Do not use these functions! π¨
ngl, the reason is actually interesting: they cannot be portably used, because they give you no way to specify the direction of growth of the stack, nor the range of the stack. it's giving "pointer with no context".
for example β on architectures with a stack that grows downward, stackaddr specifies the next address past the highest address of the allocated stack area. but on architectures with a stack that grows upward, stackaddr specifies the lowest address in the allocated stack area. same argument, completely different meaning depending on the CPU. that's a vibe check failure fr fr. π΅βπ«
by contrast, the stackaddr used by pthread_attr_setstack(3) and pthread_attr_getstack(3) is always a pointer to the lowest address in the allocated stack area β and the stacksize argument specifies the range of the stack. consistent. predictable. ate. π₯
π SEE ALSO π
pthread_attr_init(3)pthread_attr_setstack(3)pthread_attr_setstacksize(3)pthread_create(3)pthreads(7)
and that's the whole page, bestie!! π this was Linux man-pages 6.20, dated 2025-05-17 β go read pthread_attr_setstack(3) instead, ily, bye!! β¨ππΈ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms