OSDN Git Service

6f2e165c4e12eb87101ee28565aaa059ae7efd3f
[linuxjm/LDP_man-pages.git] / original / man3 / pthread_attr_setstacksize.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .TH PTHREAD_ATTR_SETSTACKSIZE 3 2008-11-05 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 pthread_attr_setstacksize, pthread_attr_getstacksize \- set/get stack size
27 attribute in thread attributes object
28 .SH SYNOPSIS
29 .nf
30 .B #include <pthread.h>
31
32 .BI "int pthread_attr_setstacksize(pthread_attr_t *" attr \
33 ", size_t " stacksize );
34 .BI "int pthread_attr_getstacksize(pthread_attr_t *" attr \
35 ", size_t *" stacksize );
36 .sp
37 Compile and link with \fI\-pthread\fP.
38 .SH DESCRIPTION
39 The
40 .BR pthread_attr_setstacksize ()
41 function sets the stack size attribute of the
42 thread attributes object referred to by
43 .I attr
44 to the value specified in
45 .IR stacksize .
46
47 The stack size attribute determines the minimum size (in bytes) that
48 will be allocated for threads created using the thread attributes object
49 .IR attr .
50
51 The
52 .BR pthread_attr_getstacksize ()
53 function returns the stack size attribute of the
54 thread attributes object referred to by
55 .I attr
56 in the buffer pointed to by
57 .IR stacksize .
58 .SH RETURN VALUE
59 On success, these functions return 0;
60 on error, they return a nonzero error number.
61 .SH ERRORS
62 .BR pthread_attr_setstacksize ()
63 can fail with the following error:
64 .TP
65 .B EINVAL
66 The stack size is less than
67 .BR PTHREAD_STACK_MIN
68 (16384) bytes.
69 .PP
70 On some systems,
71 .\" e.g., MacOS
72 .BR pthread_attr_setstacksize ()
73 can fail with the error
74 .B EINVAL
75 if
76 .I stacksize
77 is not a multiple of the system page size.
78 .SH VERSIONS
79 These functions are provided by glibc since version 2.1.
80 .SH CONFORMING TO
81 POSIX.1-2001.
82 .SH EXAMPLE
83 See
84 .BR pthread_create (3).
85 .SH NOTES
86 For details on the default stack size of new threads, see
87 .BR pthread_create (3).
88
89 A thread's stack size is fixed at the time of thread creation.
90 Only the main thread can dynamically grow its stack.
91
92 The
93 .BR pthread_attr_setstack (3)
94 function allows an application to set both the size and location
95 of a caller-allocated stack that is to be used by a thread.
96 .SH BUGS
97 As at glibc 2.8,
98 if the specified
99 .I stacksize
100 is not a multiple of
101 .BR STACK_ALIGN
102 (16 bytes on most architectures), it may be rounded
103 .IR downward ,
104 in violation of POSIX.1-2001, which says that the allocated stack will
105 be at least
106 .I stacksize
107 bytes.
108 .SH SEE ALSO
109 .BR getrlimit (2),
110 .BR pthread_attr_init (3),
111 .BR pthread_attr_setguardsize (3),
112 .BR pthread_attr_setstack (3),
113 .BR pthread_create (3),
114 .BR pthreads (7)