OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / original / man3 / pthread_attr_setstack.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH PTHREAD_ATTR_SETSTACK 3 2014-05-28 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
29 attributes in thread attributes object
30 .SH SYNOPSIS
31 .nf
32 .B #include <pthread.h>
33
34 .BI "int pthread_attr_setstack(pthread_attr_t *" attr ,
35 .BI "                          void *" stackaddr ", size_t " stacksize );
36 .BI "int pthread_attr_getstack(const pthread_attr_t *" attr ,
37 .BI "                          void **" stackaddr ", size_t *" stacksize );
38 .sp
39 Compile and link with \fI\-pthread\fP.
40 .fi
41 .sp
42 .in -4n
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
45 .in
46 .sp
47 .ad l
48 .BR pthread_attr_getstack (),
49 .BR pthread_attr_setstack ():
50 .RS 4
51 _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
52 .RE
53 .ad b
54 .SH DESCRIPTION
55 The
56 .BR pthread_attr_setstack ()
57 function sets the stack address and stack size attributes of the
58 thread attributes object referred to by
59 .I attr
60 to the values specified in
61 .IR stackaddr
62 and
63 .IR stacksize ,
64 respectively.
65 These attributes specify the location and size of the stack that should
66 be used by a thread that is created using the thread attributes object
67 .IR attr .
68
69 .I stackaddr
70 should point to the lowest addressable byte of a buffer of
71 .I stacksize
72 bytes that was allocated by the caller.
73 The pages of the allocated buffer should be both readable and writable.
74
75 The
76 .BR pthread_attr_getstack ()
77 function returns the stack address and stack size attributes of the
78 thread attributes object referred to by
79 .I attr
80 in the buffers pointed to by
81 .IR stackaddr
82 and
83 .IR stacksize ,
84 respectively.
85 .SH RETURN VALUE
86 On success, these functions return 0;
87 on error, they return a nonzero error number.
88 .SH ERRORS
89 .BR pthread_attr_setstack ()
90 can fail with the following error:
91 .TP
92 .B EINVAL
93 .I stacksize
94 is less than
95 .BR PTHREAD_STACK_MIN
96 (16384) bytes.
97 On some systems, this error may also occur if
98 .IR stackaddr
99 or
100 .IR "stackaddr\ +\ stacksize"
101 is not suitably aligned.
102 .PP
103 POSIX.1-2001 also documents an
104 .BR EACCES
105 error if the stack area described by
106 .I stackaddr
107 and
108 .I stacksize
109 is not both readable and writable by the caller.
110 .SH VERSIONS
111 These functions are provided by glibc since version 2.2.
112 .SH ATTRIBUTES
113 .SS Multithreading (see pthreads(7))
114 The
115 .BR pthread_attr_setstack ()
116 and
117 .BR pthread_attr_getstack ()
118 functions are thread-safe.
119 .SH CONFORMING TO
120 POSIX.1-2001.
121 .SH NOTES
122 These functions are provided for applications that must ensure that
123 a thread's stack is placed in a particular location.
124 For most applications, this is not necessary,
125 and the use of these functions should be avoided.
126 (Use
127 .BR pthread_attr_setstacksize (3)
128 if an application simply requires a stack size other than the default.)
129
130 When an application employs
131 .BR pthread_attr_setstack (),
132 it takes over the responsibility of allocating the stack.
133 Any guard size value that was set using
134 .BR pthread_attr_setguardsize (3)
135 is ignored.
136 If deemed necessary,
137 it is the application's responsibility to allocate a guard area
138 (one or more pages protected against reading and writing)
139 to handle the possibility of stack overflow.
140
141 The address specified in
142 .I stackaddr
143 should be suitably aligned:
144 for full portability, align it on a page boundary
145 .RI ( sysconf(_SC_PAGESIZE) ).
146 .BR posix_memalign (3)
147 may be useful for allocation.
148 Probably,
149 .IR stacksize
150 should also be a multiple of the system page size.
151
152 If
153 .I attr
154 is used to create multiple threads, then the caller must change the
155 stack address attribute between calls to
156 .BR pthread_create (3);
157 otherwise, the threads will attempt to use the same memory area
158 for their stacks, and chaos will ensue.
159 .SH EXAMPLE
160 See
161 .BR pthread_attr_init (3).
162 .SH SEE ALSO
163 .ad l
164 .nh
165 .BR mmap (2),
166 .BR mprotect (2),
167 .BR posix_memalign (3),
168 .BR pthread_attr_init (3),
169 .BR pthread_attr_setguardsize (3),
170 .BR pthread_attr_setstackaddr (3),
171 .BR pthread_attr_setstacksize (3),
172 .BR pthread_create (3),
173 .BR pthreads (7)
174 .SH COLOPHON
175 This page is part of release 3.79 of the Linux
176 .I man-pages
177 project.
178 A description of the project,
179 information about reporting bugs,
180 and the latest version of this page,
181 can be found at
182 \%http://www.kernel.org/doc/man\-pages/.