Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


pthread_attr_setstack(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |ATTRIBUTES |STANDARDS |HISTORY |NOTES |EXAMPLES |SEE ALSO |COLOPHON

pthread_attr_setstack(3) Library Functions Manualpthread_attr_setstack(3)

NAME        top

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

LIBRARY        top

       POSIX threads library (libpthread,-lpthread)

SYNOPSIS        top

#include <pthread.h>int pthread_attr_setstack(size_t stacksize;pthread_attr_t *attr,voidstackaddr[stacksize],size_tstacksize);int pthread_attr_getstack(const pthread_attr_t *restrictattr,void **restrictstackaddr,size_t *restrictstacksize);   Feature Test Macro Requirements for glibc (seefeature_test_macros(7)):pthread_attr_getstack(),pthread_attr_setstack():           _POSIX_C_SOURCE >= 200112L

DESCRIPTION        top

       Thepthread_attr_setstack() function sets the stack address and       stack size attributes of the thread attributes object referred to       byattr to the values specified instackaddr andstacksize,       respectively.  These attributes specify the location and size of       the stack that should be used by a thread that is created using       the thread attributes objectattr.stackaddr should point to the lowest addressable byte of a buffer       ofstacksize bytes that was allocated by the caller.  The pages of       the allocated buffer should be both readable and writable.       Thepthread_attr_getstack() function returns the stack address and       stack size attributes of the thread attributes object referred to       byattr in the buffers pointed to bystackaddr andstacksize,       respectively.

RETURN VALUE        top

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

ERRORS        top

pthread_attr_setstack() can fail with the following error:EINVALstacksize is less thanPTHREAD_STACK_MIN(16384) bytes.  On              some systems, this error may also occur ifstackaddr orstackaddr + stacksize is not suitably aligned.       POSIX.1 also documents anEACCESerror if the stack area described       bystackaddr andstacksize is not both readable and writable by       the caller.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7).       ┌──────────────────────────────────────┬───────────────┬─────────┐       │InterfaceAttributeValue│       ├──────────────────────────────────────┼───────────────┼─────────┤       │pthread_attr_setstack(),             │ Thread safety │ MT-Safe │       │pthread_attr_getstack()              │               │         │       └──────────────────────────────────────┴───────────────┴─────────┘

STANDARDS        top

       POSIX.1-2008.

HISTORY        top

       glibc 2.2.  POSIX.1-2001.

NOTES        top

       These functions are provided for applications that must ensure       that a thread's stack is placed in a particular location.  For       most applications, this is not necessary, and the use of these       functions should be avoided.  (Usepthread_attr_setstacksize(3) if       an application simply requires a stack size other than the       default.)       When an application employspthread_attr_setstack(), it takes over       the responsibility of allocating the stack.  Any guard size value       that was set usingpthread_attr_setguardsize(3) is ignored.  If       deemed necessary, it is the application's responsibility to       allocate a guard area (one or more pages protected against reading       and writing) to handle the possibility of stack overflow.       The address specified instackaddr should be suitably aligned: for       full portability, align it on a page boundary       (sysconf(_SC_PAGESIZE)).posix_memalign(3) may be useful for       allocation.  Probably,stacksize should also be a multiple of the       system page size.       Ifattr is used to create multiple threads, then the caller must       change the stack address attribute between calls topthread_create(3); otherwise, the threads will attempt to use the       same memory area for their stacks, and chaos will ensue.

EXAMPLES        top

       Seepthread_attr_init(3).

SEE ALSO        top

mmap(2),mprotect(2),posix_memalign(3),pthread_attr_init(3),pthread_attr_setguardsize(3),pthread_attr_setstackaddr(3),pthread_attr_setstacksize(3),pthread_create(3),pthreads(7)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-06-28pthread_attr_setstack(3)

Pages that refer to this page:pthread_attr_init(3)pthread_attr_setguardsize(3)pthread_attr_setstackaddr(3)pthread_attr_setstacksize(3)pthread_getattr_default_np(3)pthread_getattr_np(3)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp