1pthread_attr_setstacksize(3)Library Functions Manualpthread_attr_setstacksize(3)
2
3
4
6 pthread_attr_setstacksize, pthread_attr_getstacksize - set/get stack
7 size attribute in thread attributes object
8
10 POSIX threads library (libpthread, -lpthread)
11
13 #include <pthread.h>
14
15 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
16 int pthread_attr_getstacksize(const pthread_attr_t *restrict attr,
17 size_t *restrict stacksize);
18
20 The pthread_attr_setstacksize() function sets the stack size attribute
21 of the thread attributes object referred to by attr to the value speci‐
22 fied in stacksize.
23
24 The stack size attribute determines the minimum size (in bytes) that
25 will be allocated for threads created using the thread attributes ob‐
26 ject attr.
27
28 The pthread_attr_getstacksize() function returns the stack size attri‐
29 bute of the thread attributes object referred to by attr in the buffer
30 pointed to by stacksize.
31
33 On success, these functions return 0; on error, they return a nonzero
34 error number.
35
37 pthread_attr_setstacksize() can fail with the following error:
38
39 EINVAL The stack size is less than PTHREAD_STACK_MIN (16384) bytes.
40
41 On some systems, pthread_attr_setstacksize() can fail with the error
42 EINVAL if stacksize is not a multiple of the system page size.
43
45 For an explanation of the terms used in this section, see at‐
46 tributes(7).
47
48 ┌────────────────────────────────────────────┬───────────────┬─────────┐
49 │Interface │ Attribute │ Value │
50 ├────────────────────────────────────────────┼───────────────┼─────────┤
51 │pthread_attr_setstacksize(), │ Thread safety │ MT-Safe │
52 │pthread_attr_getstacksize() │ │ │
53 └────────────────────────────────────────────┴───────────────┴─────────┘
54
56 These functions are provided since glibc 2.1.
57
59 POSIX.1-2001, POSIX.1-2008.
60
62 For details on the default stack size of new threads, see pthread_cre‐
63 ate(3).
64
65 A thread's stack size is fixed at the time of thread creation. Only
66 the main thread can dynamically grow its stack.
67
68 The pthread_attr_setstack(3) function allows an application to set both
69 the size and location of a caller-allocated stack that is to be used by
70 a thread.
71
73 As at glibc 2.8, if the specified stacksize is not a multiple of
74 STACK_ALIGN (16 bytes on most architectures), it may be rounded down‐
75 ward, in violation of POSIX.1, which says that the allocated stack will
76 be at least stacksize bytes.
77
79 See pthread_create(3).
80
82 getrlimit(2), pthread_attr_init(3), pthread_attr_setguardsize(3),
83 pthread_attr_setstack(3), pthread_create(3), pthreads(7)
84
85
86
87Linux man-pages 6.04 2023-03-17 pthread_attr_setstacksize(3)