Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


pthread_getattr_default_np(3) — Linux manual page

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

pthread_g...efault_np(3) Library Functions Manualpthread_g...efault_np(3)

NAME        top

       pthread_getattr_default_np, pthread_setattr_default_np, - get or       set default thread-creation attributes

LIBRARY        top

       POSIX threads library (libpthread,-lpthread)

SYNOPSIS        top

#define _GNU_SOURCE/* See feature_test_macros(7) */#include <pthread.h>int pthread_getattr_default_np(pthread_attr_t *attr);int pthread_setattr_default_np(const pthread_attr_t *attr);

DESCRIPTION        top

       Thepthread_setattr_default_np() function sets the default       attributes used for creation of a new thread—that is, the       attributes that are used whenpthread_create(3) is called with a       second argument that is NULL.  The default attributes are set       using the attributes supplied in*attr, a previously initialized       thread attributes object.  Note the following details about the       supplied attributes object:       •  The attribute settings in the object must be valid.       •  Thestack address attribute must not be set in the object.       •  Setting thestack size attribute to zero means leave the          default stack size unchanged.       Thepthread_getattr_default_np() function initializes the thread       attributes object referred to byattr so that it contains the       default attributes used for thread creation.

ERRORS        top

EINVAL(pthread_setattr_default_np()) One of the attribute              settings inattr is invalid, or the stack address attribute              is set inattr.ENOMEM(pthread_setattr_default_np()) Insufficient memory.

ATTRIBUTES        top

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

STANDARDS        top

       GNU; hence the suffix "_np" (nonportable) in their names.

HISTORY        top

       glibc 2.18.

EXAMPLES        top

       The program below usespthread_getattr_default_np() to fetch the       default thread-creation attributes and then displays various       settings from the returned thread attributes object.  When running       the program, we see the following output:           $./a.out;           Stack size:          8388608           Guard size:          4096           Scheduling policy:   SCHED_OTHER           Scheduling priority: 0           Detach state:        JOINABLE           Inherit scheduler:   INHERITProgram source       #define _GNU_SOURCE       #include <err.h>       #include <pthread.h>       #include <sched.h>       #include <stdio.h>       #include <stdlib.h>       static void       display_pthread_attr(pthread_attr_t *attr)       {           int s;           size_t stacksize;           size_t guardsize;           int policy;           struct sched_param schedparam;           int detachstate;           int inheritsched;           s = pthread_attr_getstacksize(attr, &stacksize);           if (s != 0)               errc(EXIT_FAILURE, s, "pthread_attr_getstacksize");           printf("Stack size:          %zu\n", stacksize);           s = pthread_attr_getguardsize(attr, &guardsize);           if (s != 0)               errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");           printf("Guard size:          %zu\n", guardsize);           s = pthread_attr_getschedpolicy(attr, &policy);           if (s != 0)               errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy");           printf("Scheduling policy:   %s\n",                  (policy == SCHED_FIFO) ? "SCHED_FIFO" :                  (policy == SCHED_RR) ? "SCHED_RR" :                  (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");           s = pthread_attr_getschedparam(attr, &schedparam);           if (s != 0)               errc(EXIT_FAILURE, s, "pthread_attr_getschedparam");           printf("Scheduling priority: %d\n", schedparam.sched_priority);           s = pthread_attr_getdetachstate(attr, &detachstate);           if (s != 0)               errc(EXIT_FAILURE, s, "pthread_attr_getdetachstate");           printf("Detach state:        %s\n",                  (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :                  (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :                  "???");           s = pthread_attr_getinheritsched(attr, &inheritsched);           if (s != 0)               errc(EXIT_FAILURE, s, "pthread_attr_getinheritsched");           printf("Inherit scheduler:   %s\n",                  (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :                  (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :                  "???");       }       int       main(void)       {           int s;           pthread_attr_t attr;           s = pthread_getattr_default_np(&attr);           if (s != 0)               errc(EXIT_FAILURE, s, "pthread_getattr_default_np");           display_pthread_attr(&attr);           exit(EXIT_SUCCESS);       }

SEE ALSO        top

pthread_attr_getaffinity_np(3),pthread_attr_getdetachstate(3),pthread_attr_getguardsize(3),pthread_attr_getinheritsched(3),pthread_attr_getschedparam(3),pthread_attr_getschedpolicy(3),pthread_attr_getscope(3),pthread_attr_getstack(3),pthread_attr_getstackaddr(3),pthread_attr_getstacksize(3),pthread_attr_init(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-05-17pthread_g...efault_np(3)

Pages that refer to this page:pthread_attr_init(3)pthread_create(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