Debian Codegraph @

upstream/debian-trixie/man3/pthread_attr_setstacksize.3

raw
1 '\" t
2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\" <[email protected]>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH pthread_attr_setstacksize 3 2024-05-02 "Linux man-pages 6.9.1"
8 .SH NAME
9 pthread_attr_setstacksize, pthread_attr_getstacksize \- set/get stack size
10 attribute 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>
17 .P
18 .BI "int pthread_attr_setstacksize(pthread_attr_t *" attr \
19 ", size_t " stacksize );
20 .BI "int pthread_attr_getstacksize(const pthread_attr_t *restrict " attr ,
21 .BI " size_t *restrict " stacksize );
22 .fi
23 .SH DESCRIPTION
24 The
25 .BR pthread_attr_setstacksize ()
26 function sets the stack size attribute of the
27 thread attributes object referred to by
28 .I attr
29 to the value specified in
30 .IR stacksize .
31 .P
32 The stack size attribute determines the minimum size (in bytes) that
33 will be allocated for threads created using the thread attributes object
34 .IR attr .
35 .P
36 The
37 .BR pthread_attr_getstacksize ()
38 function returns the stack size attribute of the
39 thread attributes object referred to by
40 .I attr
41 in the buffer pointed to by
42 .IR stacksize .
43 .SH RETURN VALUE
44 On success, these functions return 0;
45 on error, they return a nonzero error number.
46 .SH ERRORS
47 .BR pthread_attr_setstacksize ()
48 can fail with the following error:
49 .TP
50 .B EINVAL
51 The stack size is less than
52 .B PTHREAD_STACK_MIN
53 (16384) bytes.
54 .P
55 On some systems,
56 .\" e.g., MacOS
57 .BR pthread_attr_setstacksize ()
58 can fail with the error
59 .B EINVAL
60 if
61 .I stacksize
62 is not a multiple of the system page size.
63 .SH ATTRIBUTES
64 For an explanation of the terms used in this section, see
65 .BR attributes (7).
66 .TS
67 allbox;
68 lbx lb lb
69 l l l.
70 Interface Attribute Value
71 T{
72 .na
73 .nh
74 .BR pthread_attr_setstacksize (),
75 .BR pthread_attr_getstacksize ()
76 T} Thread safety MT-Safe
77 .TE
78 .SH VERSIONS
79 These functions are provided since glibc 2.1.
80 .SH STANDARDS
81 POSIX.1-2001, POSIX.1-2008.
82 .SH NOTES
83 For details on the default stack size of new threads, see
84 .BR pthread_create (3).
85 .P
86 A thread's stack size is fixed at the time of thread creation.
87 Only the main thread can dynamically grow its stack.
88 .P
89 The
90 .BR pthread_attr_setstack (3)
91 function allows an application to set both the size and location
92 of a caller-allocated stack that is to be used by a thread.
93 .SH BUGS
94 As at glibc 2.8,
95 if the specified
96 .I stacksize
97 is not a multiple of
98 .B STACK_ALIGN
99 (16 bytes on most architectures), it may be rounded
100 .IR downward ,
101 in violation of POSIX.1, which says that the allocated stack will
102 be at least
103 .I stacksize
104 bytes.
105 .SH EXAMPLES
106 See
107 .BR pthread_create (3).
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)