1PTHREAD_ATTR_SETSTACK(3)   Linux Programmer's Manual  PTHREAD_ATTR_SETSTACK(3)
2
3
4

NAME

6       pthread_attr_setstack, pthread_attr_getstack - set/get stack attributes
7       in thread attributes object
8

SYNOPSIS

10       #include <pthread.h>
11
12       int pthread_attr_setstack(pthread_attr_t *attr,
13                                 void *stackaddr, size_t stacksize);
14       int pthread_attr_getstack(const pthread_attr_t *restrict attr,
15                                 void **restrict stackaddr,
16                                 size_t *restrict stacksize);
17
18       Compile and link with -pthread.
19
20   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22       pthread_attr_getstack(), pthread_attr_setstack():
23           _POSIX_C_SOURCE >= 200112L
24

DESCRIPTION

26       The pthread_attr_setstack() function sets the stack address  and  stack
27       size  attributes of the thread attributes object referred to by attr to
28       the values specified in stackaddr and stacksize,  respectively.   These
29       attributes  specify  the  location and size of the stack that should be
30       used by a thread that is created using  the  thread  attributes  object
31       attr.
32
33       stackaddr  should  point  to the lowest addressable byte of a buffer of
34       stacksize bytes that was allocated by the caller.  The pages of the al‐
35       located buffer should be both readable and writable.
36
37       The  pthread_attr_getstack()  function  returns  the  stack address and
38       stack size attributes of the thread attributes object  referred  to  by
39       attr  in  the  buffers  pointed  to by stackaddr and stacksize, respec‐
40       tively.
41

RETURN VALUE

43       On success, these functions return 0; on error, they return  a  nonzero
44       error number.
45

ERRORS

47       pthread_attr_setstack() can fail with the following error:
48
49       EINVAL stacksize is less than PTHREAD_STACK_MIN (16384) bytes.  On some
50              systems, this error  may  also  occur  if  stackaddr  or  stack‐
51              addr + stacksize is not suitably aligned.
52
53       POSIX.1  also  documents an EACCES error if the stack area described by
54       stackaddr and stacksize is  not  both  readable  and  writable  by  the
55       caller.
56

VERSIONS

58       These functions are provided by glibc since version 2.2.
59

ATTRIBUTES

61       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
62       tributes(7).
63
64       ┌────────────────────────────────────────────┬───────────────┬─────────┐
65Interface                                   Attribute     Value   
66       ├────────────────────────────────────────────┼───────────────┼─────────┤
67pthread_attr_setstack(),                    │ Thread safety │ MT-Safe │
68pthread_attr_getstack()                     │               │         │
69       └────────────────────────────────────────────┴───────────────┴─────────┘
70

CONFORMING TO

72       POSIX.1-2001, POSIX.1-2008.
73

NOTES

75       These  functions  are provided for applications that must ensure that a
76       thread's stack is placed in a particular location.  For  most  applica‐
77       tions,  this is not necessary, and the use of these functions should be
78       avoided.  (Use pthread_attr_setstacksize(3) if  an  application  simply
79       requires a stack size other than the default.)
80
81       When  an application employs pthread_attr_setstack(), it takes over the
82       responsibility of allocating the stack.  Any guard size value that  was
83       set  using  pthread_attr_setguardsize(3)  is ignored.  If deemed neces‐
84       sary, it is the application's responsibility to allocate a  guard  area
85       (one or more pages protected against reading and writing) to handle the
86       possibility of stack overflow.
87
88       The address specified in stackaddr should be suitably aligned: for full
89       portability,  align  it  on  a  page  boundary (sysconf(_SC_PAGESIZE)).
90       posix_memalign(3) may be useful for  allocation.   Probably,  stacksize
91       should also be a multiple of the system page size.
92
93       If attr is used to create multiple threads, then the caller must change
94       the stack address attribute between calls to pthread_create(3);  other‐
95       wise,  the  threads  will attempt to use the same memory area for their
96       stacks, and chaos will ensue.
97

EXAMPLES

99       See pthread_attr_init(3).
100

SEE ALSO

102       mmap(2), mprotect(2), posix_memalign(3), pthread_attr_init(3),
103       pthread_attr_setguardsize(3), pthread_attr_setstackaddr(3),
104       pthread_attr_setstacksize(3), pthread_create(3), pthreads(7)
105

COLOPHON

107       This page is part of release 5.12 of the Linux man-pages project.  A
108       description of the project, information about reporting bugs, and the
109       latest version of this page, can be found at
110       https://www.kernel.org/doc/man-pages/.
111
112
113
114Linux                             2021-03-22          PTHREAD_ATTR_SETSTACK(3)
Impressum