| 1 |
'\" t |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH pthread_attr_setstacksize 3 2025-05-17 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
pthread_attr_setstacksize, pthread_attr_getstacksize \- set/get stack size |
| 9 |
attribute in thread attributes object |
| 10 |
.SH LIBRARY |
| 11 |
POSIX threads library |
| 12 |
.RI ( libpthread ,\~ \-lpthread ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <pthread.h> |
| 16 |
.P |
| 17 |
.BI "int pthread_attr_setstacksize(pthread_attr_t *" attr \ |
| 18 |
", size_t " stacksize ); |
| 19 |
.BI "int pthread_attr_getstacksize(const pthread_attr_t *restrict " attr , |
| 20 |
.BI " size_t *restrict " stacksize ); |
| 21 |
.fi |
| 22 |
.SH DESCRIPTION |
| 23 |
The |
| 24 |
.BR pthread_attr_setstacksize () |
| 25 |
function sets the stack size attribute of the |
| 26 |
thread attributes object referred to by |
| 27 |
.I attr |
| 28 |
to the value specified in |
| 29 |
.IR stacksize . |
| 30 |
.P |
| 31 |
The stack size attribute determines the minimum size (in bytes) that |
| 32 |
will be allocated for threads created using the thread attributes object |
| 33 |
.IR attr . |
| 34 |
.P |
| 35 |
The |
| 36 |
.BR pthread_attr_getstacksize () |
| 37 |
function returns the stack size attribute of the |
| 38 |
thread attributes object referred to by |
| 39 |
.I attr |
| 40 |
in the buffer pointed to by |
| 41 |
.IR stacksize . |
| 42 |
.SH RETURN VALUE |
| 43 |
On success, these functions return 0; |
| 44 |
on error, they return a nonzero error number. |
| 45 |
.SH ERRORS |
| 46 |
.BR pthread_attr_setstacksize () |
| 47 |
can fail with the following error: |
| 48 |
.TP |
| 49 |
.B EINVAL |
| 50 |
The stack size is less than |
| 51 |
.B PTHREAD_STACK_MIN |
| 52 |
(16384) bytes. |
| 53 |
.P |
| 54 |
On some systems, |
| 55 |
.\" e.g., MacOS |
| 56 |
.BR pthread_attr_setstacksize () |
| 57 |
can fail with the error |
| 58 |
.B EINVAL |
| 59 |
if |
| 60 |
.I stacksize |
| 61 |
is not a multiple of the system page size. |
| 62 |
.SH ATTRIBUTES |
| 63 |
For an explanation of the terms used in this section, see |
| 64 |
.BR attributes (7). |
| 65 |
.TS |
| 66 |
allbox; |
| 67 |
lbx lb lb |
| 68 |
l l l. |
| 69 |
Interface Attribute Value |
| 70 |
T{ |
| 71 |
.na |
| 72 |
.nh |
| 73 |
.BR pthread_attr_setstacksize (), |
| 74 |
.BR pthread_attr_getstacksize () |
| 75 |
T} Thread safety MT-Safe |
| 76 |
.TE |
| 77 |
.SH VERSIONS |
| 78 |
These functions are provided since glibc 2.1. |
| 79 |
.SH STANDARDS |
| 80 |
POSIX.1-2001, POSIX.1-2008. |
| 81 |
.SH NOTES |
| 82 |
For details on the default stack size of new threads, see |
| 83 |
.BR pthread_create (3). |
| 84 |
.P |
| 85 |
A thread's stack size is fixed at the time of thread creation. |
| 86 |
Only the main thread can dynamically grow its stack. |
| 87 |
.P |
| 88 |
The |
| 89 |
.BR pthread_attr_setstack (3) |
| 90 |
function allows an application to set both the size and location |
| 91 |
of a caller-allocated stack that is to be used by a thread. |
| 92 |
.SH BUGS |
| 93 |
As at glibc 2.8, |
| 94 |
if the specified |
| 95 |
.I stacksize |
| 96 |
is not a multiple of |
| 97 |
.B STACK_ALIGN |
| 98 |
(16 bytes on most architectures), it may be rounded |
| 99 |
.IR downward , |
| 100 |
in violation of POSIX.1, which says that the allocated stack will |
| 101 |
be at least |
| 102 |
.I stacksize |
| 103 |
bytes. |
| 104 |
.SH EXAMPLES |
| 105 |
See |
| 106 |
.BR pthread_create (3). |
| 107 |
.SH SEE ALSO |
| 108 |
.BR getrlimit (2), |
| 109 |
.BR pthread_attr_init (3), |
| 110 |
.BR pthread_attr_setguardsize (3), |
| 111 |
.BR pthread_attr_setstack (3), |
| 112 |
.BR pthread_create (3), |
| 113 |
.BR pthreads (7) |