share/mk/: Remove unused variable
[man-pages.git] / man3 / pthread_attr_setstack.3
blobf783b03a516752d1ddcce4e7ae36b8978cbf18dc
1 '\" t
2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH pthread_attr_setstack 3 (date) "Linux man-pages (unreleased)"
8 .SH NAME
9 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
10 attributes in thread attributes object
11 .SH LIBRARY
12 POSIX threads library
13 .RI ( libpthread ", " \-lpthread )
14 .SH SYNOPSIS
15 .nf
16 .B #include <pthread.h>
18 .BI "int pthread_attr_setstack(pthread_attr_t *" attr ,
19 .BI "                          void " stackaddr [. stacksize ],
20 .BI "                          size_t " stacksize );
21 .BI "int pthread_attr_getstack(const pthread_attr_t *restrict " attr ,
22 .BI "                          void **restrict " stackaddr ,
23 .BI "                          size_t *restrict " stacksize );
24 .fi
26 .RS -4
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
29 .RE
31 .BR pthread_attr_getstack (),
32 .BR pthread_attr_setstack ():
33 .nf
34     _POSIX_C_SOURCE >= 200112L
35 .fi
36 .SH DESCRIPTION
37 The
38 .BR pthread_attr_setstack ()
39 function sets the stack address and stack size attributes of the
40 thread attributes object referred to by
41 .I attr
42 to the values specified in
43 .I stackaddr
44 and
45 .IR stacksize ,
46 respectively.
47 These attributes specify the location and size of the stack that should
48 be used by a thread that is created using the thread attributes object
49 .IR attr .
51 .I stackaddr
52 should point to the lowest addressable byte of a buffer of
53 .I stacksize
54 bytes that was allocated by the caller.
55 The pages of the allocated buffer should be both readable and writable.
57 The
58 .BR pthread_attr_getstack ()
59 function returns the stack address and stack size attributes of the
60 thread attributes object referred to by
61 .I attr
62 in the buffers pointed to by
63 .I stackaddr
64 and
65 .IR stacksize ,
66 respectively.
67 .SH RETURN VALUE
68 On success, these functions return 0;
69 on error, they return a nonzero error number.
70 .SH ERRORS
71 .BR pthread_attr_setstack ()
72 can fail with the following error:
73 .TP
74 .B EINVAL
75 .I stacksize
76 is less than
77 .B PTHREAD_STACK_MIN
78 (16384) bytes.
79 On some systems, this error may also occur if
80 .I stackaddr
82 .I stackaddr\~+\~stacksize
83 is not suitably aligned.
85 POSIX.1 also documents an
86 .B EACCES
87 error if the stack area described by
88 .I stackaddr
89 and
90 .I stacksize
91 is not both readable and writable by the caller.
92 .SH ATTRIBUTES
93 For an explanation of the terms used in this section, see
94 .BR attributes (7).
95 .TS
96 allbox;
97 lbx lb lb
98 l l l.
99 Interface       Attribute       Value
103 .BR pthread_attr_setstack (),
104 .BR pthread_attr_getstack ()
105 T}      Thread safety   MT-Safe
107 .SH STANDARDS
108 POSIX.1-2008.
109 .SH HISTORY
110 glibc 2.2.
111 POSIX.1-2001.
112 .SH NOTES
113 These functions are provided for applications that must ensure that
114 a thread's stack is placed in a particular location.
115 For most applications, this is not necessary,
116 and the use of these functions should be avoided.
117 (Use
118 .BR pthread_attr_setstacksize (3)
119 if an application simply requires a stack size other than the default.)
121 When an application employs
122 .BR pthread_attr_setstack (),
123 it takes over the responsibility of allocating the stack.
124 Any guard size value that was set using
125 .BR pthread_attr_setguardsize (3)
126 is ignored.
127 If deemed necessary,
128 it is the application's responsibility to allocate a guard area
129 (one or more pages protected against reading and writing)
130 to handle the possibility of stack overflow.
132 The address specified in
133 .I stackaddr
134 should be suitably aligned:
135 for full portability, align it on a page boundary
136 .RI ( sysconf(_SC_PAGESIZE) ).
137 .BR posix_memalign (3)
138 may be useful for allocation.
139 Probably,
140 .I stacksize
141 should also be a multiple of the system page size.
144 .I attr
145 is used to create multiple threads, then the caller must change the
146 stack address attribute between calls to
147 .BR pthread_create (3);
148 otherwise, the threads will attempt to use the same memory area
149 for their stacks, and chaos will ensue.
150 .SH EXAMPLES
152 .BR pthread_attr_init (3).
153 .SH SEE ALSO
154 .ad l
156 .BR mmap (2),
157 .BR mprotect (2),
158 .BR posix_memalign (3),
159 .BR pthread_attr_init (3),
160 .BR pthread_attr_setguardsize (3),
161 .BR pthread_attr_setstackaddr (3),
162 .BR pthread_attr_setstacksize (3),
163 .BR pthread_create (3),
164 .BR pthreads (7)