1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH PTHREAD_ATTR_SETSTACK 3 2008-10-24 "Linux" "Linux Programmer's Manual"
26 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
27 attributes in thread attributes object
30 .B #include <pthread.h>
32 .BI "int pthread_attr_setstack(pthread_attr_t *" attr ,
33 .BI " void *" stackaddr ", size_t " stacksize );
34 .BI "int pthread_attr_getstack(pthread_attr_t *" attr ,
35 .BI " void **" stackaddr ", size_t *" stacksize );
37 Compile and link with \fI\-pthread\fP.
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
46 .BR pthread_attr_getstack (),
47 .BR pthread_attr_setstack ():
48 _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
52 .BR pthread_attr_setstack ()
53 function sets the stack address and stack size attributes of the
54 thread attributes object referred to by
56 to the values specified in
61 These attributes specify the location and size of the stack that should
62 be used by a thread that is created using the thread attributes object
66 should point to the lowest addressable byte of a buffer of
68 bytes that was allocated by the caller.
69 The pages of the allocated buffer should be both readable and writable.
72 .BR pthread_attr_getstack ()
73 function returns the stack address and stack size attributes of the
74 thread attributes object referred to by
76 in the buffers pointed to by
82 On success, these functions return 0;
83 on error, they return a nonzero error number.
85 .BR pthread_attr_setstack ()
86 can fail with the following error:
93 On some systems, this error may also occur if
96 .IR "stackaddr\ +\ stacksize"
97 is not suitably aligned.
99 POSIX.1-2001 also documents an
101 error if the stack area described by
105 is not both readable and writable by the caller.
107 These functions are provided by glibc since version 2.2.
111 These functions are provided for applications that must ensure that
112 a thread's stack is placed in a particular location.
113 For most applications, this is not necessary,
114 and the use of these functions should be avoided.
116 .BR pthread_attr_setstacksize (3)
117 if an application simply requires a stack size other than the default.)
119 When an application employs
120 .BR pthread_attr_setstack (),
121 it takes over the responsibility of allocating the stack.
122 Any guard size value that was set using
123 .BR pthread_attr_setguardsize (3)
126 it is the application's responsibility to allocate a guard area
127 (one or more pages protected against reading and writing)
128 to handle the possibility of stack overflow.
130 The address specified in
132 should be suitably aligned:
133 for full portability, align it on a page boundary
134 .RI ( sysconf(_SC_PAGESIZE) ).
135 .BR posix_memalign (3)
136 may be useful for allocation.
139 should also be a multiple of the system page size.
143 is used to create multiple threads, then the caller must change the
144 stack address attribute between calls to
145 .BR pthread_create (3);
146 otherwise, the threads will attempt to use the same memory area
147 for their stacks, and chaos will ensue.
151 .BR pthread_attr_init (3).
155 .BR posix_memalign (3),
156 .BR pthread_attr_init (3),
157 .BR pthread_attr_setguardsize (3),
158 .BR pthread_attr_setstackaddr (3),
159 .BR pthread_attr_setstacksize (3),
160 .BR pthread_create (3),