PTHREAD_A...TSTACKSIZE(3P)

πŸ’– PTHREAD_A...TSTACKSIZE(3P) πŸ’–

okay bestie, so this one's from the POSIX Programmer's Manual ✨ (that's the 3P bit in the title, iykyk).

Quick heads up before we dive in: the Linux implementation of this interface may differ from what's written here (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly? the interface might not even be implemented on Linux at all. πŸ™ˆ Just so you know.

✨ NAME ✨

pthread_attr_getstacksize, pthread_attr_setstacksize β€” get and set the stacksize attribute


🌸 SYNOPSIS 🌸

#include <pthread.h>

int pthread_attr_getstacksize(const pthread_attr_t *restrict attr,
    size_t *restrict stacksize);
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);

πŸŽ€ DESCRIPTION πŸŽ€

So pthread_attr_getstacksize() and pthread_attr_setstacksize() do exactly what they sound like: they get and set the thread creation stacksize attribute inside the attr object. Iconic, honestly.

The stacksize attribute defines the minimum stack size (in bytes, fr fr) that gets allocated for the created thread's stack. It's giving "how much room does my girl need to breathe."

πŸ’€ Now the serious bit: the behavior is undefined if the value you pass as the attr argument to pthread_attr_getstacksize() or pthread_attr_setstacksize() doesn't refer to an initialized thread attributes object. So like... initialize your stuff. Don't be messy. 🫢

πŸ’… RETURN VALUE πŸ’…

When everything goes slay, both pthread_attr_getstacksize() and pthread_attr_setstacksize() return a value of 0. Otherwise? They hand you an error number to tell you what went wrong. 😭

And if it works out, pthread_attr_getstacksize() stores the stacksize attribute value in stacksize. No cap. ✨


πŸ”₯ ERRORS πŸ”₯

The pthread_attr_setstacksize() function shall fail if:

  • EINVAL β€” the value of stacksize is less than {PTHREAD_STACK_MIN} or it exceeds a system-imposed limit. Basically: too smol or too extra. Pick a normal size bestie. πŸ₯²
⭐ These functions shall not return an error code of [EINTR]. Periodt.

The following sections are informative. (Translation: the juicy technical part is over, these are the bonus features. πŸ“)


🌈 EXAMPLES 🌈

None. πŸ’€ Nothing here. Empty. A void. Moving on.


πŸ¦‹ APPLICATION USAGE πŸ¦‹

None. Also empty. The girls are giving nothing today, and that's okay. πŸ’œ


πŸ‘‘ RATIONALE πŸ‘‘

So here's the tea: if an implementation detects that the value specified by the attr argument to pthread_attr_getstacksize() or pthread_attr_setstacksize() doesn't refer to an initialized thread attributes object, it is recommended that the function should fail and report an [EINVAL] error. Recommended, not required β€” so don't come for me if it doesn't. πŸ™ˆ


🧚 FUTURE DIRECTIONS 🧚

None. ✨ (Iconic of it to have zero plans, honestly.)


πŸ’– SEE ALSO πŸ’–

  • pthread_attr_destroy()
  • pthread_attr_getdetachstate()
  • pthread_create()

The Base Definitions volume of POSIX.1‐2017, <limits.h>, <pthread.h> πŸ“š


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie!! πŸŽ€βœ¨ this one's brought to you by IEEE/The Open Group, dated 2017, and it's a certified POSIX Programmer's Manual classic. go forth and stack responsibly πŸ’…πŸ«Ά

πŸ“¦ where this page comes from