290 lines
11 KiB
HTML
290 lines
11 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of PTHREAD_GETATTR_DEFAULT_NP</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>PTHREAD_GETATTR_DEFAULT_NP</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
pthread_getattr_default_np, pthread_setattr_default_np, -
|
|
get or set default thread-creation attributes
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#define _GNU_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
<B>#include <<A HREF="file:///usr/include/pthread.h">pthread.h</A>></B>
|
|
|
|
<B>int pthread_getattr_default_np(pthread_attr_t *</B><I>attr</I><B>);</B>
|
|
<B>int pthread_setattr_default_np(pthread_attr_t *</B><I>attr</I><B>);</B>
|
|
|
|
Compile and link with <I>-pthread</I>.
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>pthread_setattr_default_np</B>()
|
|
|
|
function sets the default attributes used for creation of a new
|
|
thread---that is, the attributes that are used when
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_create">pthread_create</A></B>(3)
|
|
|
|
is called with a second argument that is NULL.
|
|
The default attributes are set using the attributes supplied in
|
|
<I>*attr</I>,
|
|
|
|
a previously initialized thread attributes object.
|
|
Note the following details about the supplied attributes object:
|
|
<DL COMPACT>
|
|
<DT id="1">*<DD>
|
|
The attribute settings in the object must be valid.
|
|
<DT id="2">*<DD>
|
|
The
|
|
<I>stack address</I>
|
|
|
|
attribute must not be set in the object.
|
|
<DT id="3">*<DD>
|
|
Setting the
|
|
<I>stack size</I>
|
|
|
|
attribute to zero means leave the default stack size unchanged.
|
|
</DL>
|
|
<P>
|
|
|
|
The
|
|
<B>pthread_getattr_default_np</B>()
|
|
|
|
function initializes the thread attributes object referred to by
|
|
<I>attr</I>
|
|
|
|
so that it contains the default attributes used for thread creation.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="4"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
(<B>pthread_setattr_default_np</B>())
|
|
|
|
One of the attribute settings in
|
|
<I>attr</I>
|
|
|
|
is invalid, or the stack address attribute is set in
|
|
<I>attr</I>.
|
|
|
|
<DT id="5"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
|
|
(<B>pthread_setattr_default_np</B>())
|
|
|
|
Insufficient memory.
|
|
</DL>
|
|
<A NAME="lbAF"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
These functions are available in glibc since version 2.18.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>pthread_getattr_default_np</B>(),
|
|
|
|
<B>pthread_setattr_default_np</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
These functions are nonstandard GNU extensions;
|
|
hence the suffix "_np" (nonportable) in their names.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The program below uses
|
|
<B>pthread_getattr_default_np</B>()
|
|
|
|
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:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>./a.out</B>
|
|
Stack size: 8388608
|
|
Guard size: 4096
|
|
Scheduling policy: SCHED_OTHER
|
|
Scheduling priority: 0
|
|
Detach state: JOINABLE
|
|
Inherit scheduler: INHERIT
|
|
|
|
|
|
<P>
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
#include <<A HREF="file:///usr/include/pthread.h">pthread.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/errno.h">errno.h</A>>
|
|
<P>
|
|
#define errExitEN(en, msg) \
|
|
<BR> do { errno = en; perror(msg); \
|
|
<BR> exit(EXIT_FAILURE); } while (0)
|
|
<P>
|
|
static void
|
|
display_pthread_attr(pthread_attr_t *attr)
|
|
{
|
|
<BR> int s;
|
|
<BR> size_t stacksize;
|
|
<BR> size_t guardsize;
|
|
<BR> int policy;
|
|
<BR> struct sched_param schedparam;
|
|
<BR> int detachstate;
|
|
<BR> int inheritsched;
|
|
<P>
|
|
<BR> s = pthread_attr_getstacksize(attr, &stacksize);
|
|
<BR> if (s != 0)
|
|
<BR> errExitEN(s, "pthread_attr_getstacksize");
|
|
<BR> printf("Stack size: %zd\n", stacksize);
|
|
<P>
|
|
<BR> s = pthread_attr_getguardsize(attr, &guardsize);
|
|
<BR> if (s != 0)
|
|
<BR> errExitEN(s, "pthread_attr_getguardsize");
|
|
<BR> printf("Guard size: %zd\n", guardsize);
|
|
<P>
|
|
<BR> s = pthread_attr_getschedpolicy(attr, &policy);
|
|
<BR> if (s != 0)
|
|
<BR> errExitEN(s, "pthread_attr_getschedpolicy");
|
|
<BR> printf("Scheduling policy: %s\n",
|
|
<BR> (policy == SCHED_FIFO) ? "SCHED_FIFO" :
|
|
<BR> (policy == SCHED_RR) ? "SCHED_RR" :
|
|
<BR> (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
|
|
<P>
|
|
<BR> s = pthread_attr_getschedparam(attr, &schedparam);
|
|
<BR> if (s != 0)
|
|
<BR> errExitEN(s, "pthread_attr_getschedparam");
|
|
<BR> printf("Scheduling priority: %d\n", schedparam.sched_priority);
|
|
<P>
|
|
<BR> s = pthread_attr_getdetachstate(attr, &detachstate);
|
|
<BR> if (s != 0)
|
|
<BR> errExitEN(s, "pthread_attr_getdetachstate");
|
|
<BR> printf("Detach state: %s\n",
|
|
<BR> (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
|
|
<BR> (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
|
|
<BR> "???");
|
|
<P>
|
|
<BR> s = pthread_attr_getinheritsched(attr, &inheritsched);
|
|
<BR> if (s != 0)
|
|
<BR> errExitEN(s, "pthread_attr_getinheritsched");
|
|
<BR> printf("Inherit scheduler: %s\n",
|
|
<BR> (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
|
|
<BR> (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
|
|
<BR> "???");
|
|
}
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> int s;
|
|
<BR> pthread_attr_t attr;
|
|
<P>
|
|
<BR> s = pthread_getattr_default_np(&attr);
|
|
<BR> if (s != 0)
|
|
<BR> errExitEN(s, "pthread_getattr_default_np");
|
|
<P>
|
|
<BR> display_pthread_attr(&attr);
|
|
<P>
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getaffinity_np">pthread_attr_getaffinity_np</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getdetachstate">pthread_attr_getdetachstate</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getguardsize">pthread_attr_getguardsize</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getinheritsched">pthread_attr_getinheritsched</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getschedparam">pthread_attr_getschedparam</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getschedpolicy">pthread_attr_getschedpolicy</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getscope">pthread_attr_getscope</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getstack">pthread_attr_getstack</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getstackaddr">pthread_attr_getstackaddr</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_getstacksize">pthread_attr_getstacksize</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_attr_init">pthread_attr_init</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_create">pthread_create</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+pthreads">pthreads</A></B>(7)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="6"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="7"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="8"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="9"><A HREF="#lbAE">ERRORS</A><DD>
|
|
<DT id="10"><A HREF="#lbAF">VERSIONS</A><DD>
|
|
<DT id="11"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="13"><A HREF="#lbAI">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="14"><A HREF="#lbAJ">Program source</A><DD>
|
|
</DL>
|
|
<DT id="15"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="16"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:53 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|