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(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 || _XOPEN_SOURCE >= 600
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-2001 also documents an EACCES error if the stack area described
53       by stackaddr and stacksize is not both readable  and  writable  by  the
54       caller.
55

VERSIONS

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

CONFORMING TO

60       POSIX.1-2001.
61

NOTES

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

EXAMPLE

87       See pthread_attr_init(3).
88

SEE ALSO

90       mmap(2), mprotect(2), posix_memalign(3), pthread_attr_init(3),
91       pthread_attr_setguardsize(3), pthread_attr_setstackaddr(3),
92       pthread_attr_setstacksize(3), pthread_create(3), pthreads(7)
93

COLOPHON

95       This page is part of release 3.53 of the Linux man-pages project.  A
96       description of the project, and information about reporting bugs, can
97       be found at http://www.kernel.org/doc/man-pages/.
98
99
100
101Linux                             2008-10-24          PTHREAD_ATTR_SETSTACK(3)
Impressum