Blame man3/pthread_getattr_default_np.3

Packit 7cfc04
.\" Copyright (c) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH PTHREAD_GETATTR_DEFAULT_NP 3 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
pthread_getattr_default_np, pthread_setattr_default_np, \-
Packit 7cfc04
get or set default thread-creation attributes
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.BR "#define _GNU_SOURCE" "             /* See feature_test_macros(7) */"
Packit 7cfc04
.B #include <pthread.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int pthread_getattr_default_np(pthread_attr_t *" attr );
Packit 7cfc04
.BI "int pthread_setattr_default_np(pthread_attr_t *" attr );
Packit 7cfc04
.PP
Packit 7cfc04
Compile and link with \fI\-pthread\fP.
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR pthread_setattr_default_np ()
Packit 7cfc04
function sets the default attributes used for creation of a new
Packit 7cfc04
thread\(emthat is, the attributes that are used when
Packit 7cfc04
.BR pthread_create (3)
Packit 7cfc04
is called with a second argument that is NULL.
Packit 7cfc04
The default attributes are set using the attributes supplied in
Packit 7cfc04
.IR *attr ,
Packit 7cfc04
a previously initialized thread attributes object.
Packit 7cfc04
Note the following details about the supplied attributes object:
Packit 7cfc04
.IP * 3
Packit 7cfc04
The attribute settings in the object must be valid.
Packit 7cfc04
.IP *
Packit 7cfc04
The
Packit 7cfc04
.IR "stack address"
Packit 7cfc04
attribute must not be set in the object.
Packit 7cfc04
.IP *
Packit 7cfc04
Setting the
Packit 7cfc04
.IR "stack size"
Packit 7cfc04
attribute to zero means leave the default stack size unchanged.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR pthread_getattr_default_np ()
Packit 7cfc04
function initializes the thread attributes object referred to by
Packit 7cfc04
.I attr
Packit 7cfc04
so that it contains the default attributes used for thread creation.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.RB ( pthread_setattr_default_np ())
Packit 7cfc04
One of the attribute settings in
Packit 7cfc04
.IR attr
Packit 7cfc04
is invalid, or the stack address attribute is set in
Packit 7cfc04
.IR attr .
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
.\" Can happen (but unlikely) while trying to allocate memory for cpuset
Packit 7cfc04
.RB ( pthread_setattr_default_np ())
Packit 7cfc04
Insufficient memory.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
These functions are available in glibc since version 2.18.
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.ad l
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lbw30 lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR pthread_getattr_default_np (),
Packit 7cfc04
.BR pthread_setattr_default_np ()
Packit 7cfc04
T}	Thread safety	MT-Safe
Packit 7cfc04
.TE
Packit 7cfc04
.ad
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
These functions are nonstandard GNU extensions;
Packit 7cfc04
hence the suffix "_np" (nonportable) in their names.
Packit 7cfc04
.SH EXAMPLE
Packit 7cfc04
The program below uses
Packit 7cfc04
.BR pthread_getattr_default_np ()
Packit 7cfc04
to fetch the default thread-creation attributes and then displays
Packit 7cfc04
various settings from the returned thread attributes object.
Packit 7cfc04
When running the program, we see the following output:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
$ \fB./a.out\fP
Packit 7cfc04
Stack size:          8388608
Packit 7cfc04
Guard size:          4096
Packit 7cfc04
Scheduling policy:   SCHED_OTHER
Packit 7cfc04
Scheduling priority: 0
Packit 7cfc04
Detach state:        JOINABLE
Packit 7cfc04
Inherit scheduler:   INHERIT
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.SS Program source
Packit 7cfc04
\&
Packit 7cfc04
.EX
Packit 7cfc04
#define _GNU_SOURCE
Packit 7cfc04
#include <pthread.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
#include <errno.h>
Packit 7cfc04
Packit 7cfc04
#define errExitEN(en, msg) \\
Packit 7cfc04
                        do { errno = en; perror(msg); \\
Packit 7cfc04
                             exit(EXIT_FAILURE); } while (0)
Packit 7cfc04
Packit 7cfc04
static void
Packit 7cfc04
display_pthread_attr(pthread_attr_t *attr)
Packit 7cfc04
{
Packit 7cfc04
    int s;
Packit 7cfc04
    size_t stacksize;
Packit 7cfc04
    size_t guardsize;
Packit 7cfc04
    int policy;
Packit 7cfc04
    struct sched_param schedparam;
Packit 7cfc04
    int detachstate;
Packit 7cfc04
    int inheritsched;
Packit 7cfc04
Packit 7cfc04
    s = pthread_attr_getstacksize(attr, &stacksize);
Packit 7cfc04
    if (s != 0)
Packit 7cfc04
        errExitEN(s, "pthread_attr_getstacksize");
Packit 7cfc04
    printf("Stack size:          %zd\\n", stacksize);
Packit 7cfc04
Packit 7cfc04
    s = pthread_attr_getguardsize(attr, &guardsize);
Packit 7cfc04
    if (s != 0)
Packit 7cfc04
        errExitEN(s, "pthread_attr_getguardsize");
Packit 7cfc04
    printf("Guard size:          %zd\\n", guardsize);
Packit 7cfc04
Packit 7cfc04
    s = pthread_attr_getschedpolicy(attr, &policy);
Packit 7cfc04
    if (s != 0)
Packit 7cfc04
        errExitEN(s, "pthread_attr_getschedpolicy");
Packit 7cfc04
    printf("Scheduling policy:   %s\\n",
Packit 7cfc04
            (policy == SCHED_FIFO) ? "SCHED_FIFO" :
Packit 7cfc04
            (policy == SCHED_RR) ? "SCHED_RR" :
Packit 7cfc04
            (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
Packit 7cfc04
Packit 7cfc04
    s = pthread_attr_getschedparam(attr, &schedparam);
Packit 7cfc04
    if (s != 0)
Packit 7cfc04
        errExitEN(s, "pthread_attr_getschedparam");
Packit 7cfc04
    printf("Scheduling priority: %d\\n", schedparam.sched_priority);
Packit 7cfc04
Packit 7cfc04
    s = pthread_attr_getdetachstate(attr, &detachstate);
Packit 7cfc04
    if (s != 0)
Packit 7cfc04
        errExitEN(s, "pthread_attr_getdetachstate");
Packit 7cfc04
    printf("Detach state:        %s\\n",
Packit 7cfc04
            (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
Packit 7cfc04
            (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
Packit 7cfc04
            "???");
Packit 7cfc04
Packit 7cfc04
    s = pthread_attr_getinheritsched(attr, &inheritsched);
Packit 7cfc04
    if (s != 0)
Packit 7cfc04
        errExitEN(s, "pthread_attr_getinheritsched");
Packit 7cfc04
    printf("Inherit scheduler:   %s\\n",
Packit 7cfc04
            (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
Packit 7cfc04
            (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
Packit 7cfc04
            "???");
Packit 7cfc04
}
Packit 7cfc04
Packit 7cfc04
int
Packit 7cfc04
main(int argc, char *argv[])
Packit 7cfc04
{
Packit 7cfc04
    int s;
Packit 7cfc04
    pthread_attr_t attr;
Packit 7cfc04
Packit 7cfc04
    s = pthread_getattr_default_np(&attr);
Packit 7cfc04
    if (s != 0)
Packit 7cfc04
        errExitEN(s, "pthread_getattr_default_np");
Packit 7cfc04
Packit 7cfc04
    display_pthread_attr(&attr);
Packit 7cfc04
Packit 7cfc04
    exit(EXIT_SUCCESS);
Packit 7cfc04
}
Packit 7cfc04
.EE
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.ad l
Packit 7cfc04
.nh
Packit 7cfc04
.BR pthread_attr_getaffinity_np (3),
Packit 7cfc04
.BR pthread_attr_getdetachstate (3),
Packit 7cfc04
.BR pthread_attr_getguardsize (3),
Packit 7cfc04
.BR pthread_attr_getinheritsched (3),
Packit 7cfc04
.BR pthread_attr_getschedparam (3),
Packit 7cfc04
.BR pthread_attr_getschedpolicy (3),
Packit 7cfc04
.BR pthread_attr_getscope (3),
Packit 7cfc04
.BR pthread_attr_getstack (3),
Packit 7cfc04
.BR pthread_attr_getstackaddr (3),
Packit 7cfc04
.BR pthread_attr_getstacksize (3),
Packit 7cfc04
.BR pthread_attr_init (3),
Packit 7cfc04
.BR pthread_create (3),
Packit 7cfc04
.BR pthreads (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.