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 *attr,
15                                 void **stackaddr, size_t *stacksize);
16
17       Compile and link with -pthread.
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       pthread_attr_getstack(), pthread_attr_setstack():
22           _POSIX_C_SOURCE >= 200112L
23

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

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

ATTRIBUTES

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

CONFORMING TO

70       POSIX.1-2001, POSIX.1-2008.
71

NOTES

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

EXAMPLE

97       See pthread_attr_init(3).
98

SEE ALSO

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

COLOPHON

105       This page is part of release 5.02 of the Linux man-pages project.  A
106       description of the project, information about reporting bugs, and the
107       latest version of this page, can be found at
108       https://www.kernel.org/doc/man-pages/.
109
110
111
112Linux                             2017-09-15          PTHREAD_ATTR_SETSTACK(3)
Impressum