Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/pthread_attr_destroy.html
2024-02-19 00:21:47 -05:00

222 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>pthread_attr_destroy</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="pthread_attr_destroy"></a> <a name="tag_03_487"></a><!-- pthread_attr_destroy -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_487_01"></a>NAME</h4>
<blockquote>pthread_attr_destroy, pthread_attr_init - destroy and initialize the thread attributes object</blockquote>
<h4><a name="tag_03_487_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> #include &lt;<a href="../basedefs/pthread.h.html">pthread.h</a>&gt;<br>
<br>
int pthread_attr_destroy(pthread_attr_t *</tt><i>attr</i><tt>);<br>
int pthread_attr_init(pthread_attr_t *</tt><i>attr</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border=
"0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_03_487_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>pthread_attr_destroy</i>() function shall destroy a thread attributes object. An implementation may cause
<i>pthread_attr_destroy</i>() to set <i>attr</i> to an implementation-defined invalid value. A destroyed <i>attr</i> attributes
object can be reinitialized using <i>pthread_attr_init</i>(); the results of otherwise referencing the object after it has been
destroyed are undefined.</p>
<p>The <i>pthread_attr_init</i>() function shall initialize a thread attributes object <i>attr</i> with the default value for all
of the individual attributes used by a given implementation.</p>
<p>The resulting attributes object (possibly modified by setting individual attribute values) when used by <a href=
"../functions/pthread_create.html"><i>pthread_create</i>()</a> defines the attributes of the thread created. A single attributes
object can be used in multiple simultaneous calls to <a href="../functions/pthread_create.html"><i>pthread_create</i>()</a>.
Results are undefined if <i>pthread_attr_init</i>() is called specifying an already initialized <i>attr</i> attributes object.</p>
</blockquote>
<h4><a name="tag_03_487_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>pthread_attr_destroy</i>() and <i>pthread_attr_init</i>() shall return a value of 0; otherwise,
an error number shall be returned to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_487_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>pthread_attr_init</i>() function shall fail if:</p>
<dl compact>
<dt>[ENOMEM]</dt>
<dd>Insufficient memory exists to initialize the thread attributes object.</dd>
</dl>
<p>These functions shall not return an error code of [EINTR].</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_487_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_487_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_487_08"></a>RATIONALE</h4>
<blockquote>
<p>Attributes objects are provided for threads, mutexes, and condition variables as a mechanism to support probable future
standardization in these areas without requiring that the function itself be changed.</p>
<p>Attributes objects provide clean isolation of the configurable aspects of threads. For example, &quot;stack size&quot; is an important
attribute of a thread, but it cannot be expressed portably. When porting a threaded program, stack sizes often need to be adjusted.
The use of attributes objects can help by allowing the changes to be isolated in a single place, rather than being spread across
every instance of thread creation.</p>
<p>Attributes objects can be used to set up &quot;classes' of threads with similar attributes; for example, &quot;threads with large stacks
and high priority&quot; or &quot;threads with minimal stacks&quot;. These classes can be defined in a single place and then referenced wherever
threads need to be created. Changes to &quot;class&quot; decisions become straightforward, and detailed analysis of each <a href=
"../functions/pthread_create.html"><i>pthread_create</i>()</a> call is not required.</p>
<p>The attributes objects are defined as opaque types as an aid to extensibility. If these objects had been specified as
structures, adding new attributes would force recompilation of all multi-threaded programs when the attributes objects are
extended; this might not be possible if different program components were supplied by different vendors.</p>
<p>Additionally, opaque attributes objects present opportunities for improving performance. Argument validity can be checked once
when attributes are set, rather than each time a thread is created. Implementations often need to cache kernel objects that are
expensive to create. Opaque attributes objects provide an efficient mechanism to detect when cached objects become invalid due to
attribute changes.</p>
<p>Since assignment is not necessarily defined on a given opaque type, implementation-defined default values cannot be defined in a
portable way. The solution to this problem is to allow attributes objects to be initialized dynamically by attributes object
initialization functions, so that default values can be supplied automatically by the implementation.</p>
<p>The following proposal was provided as a suggested alternative to the supplied attributes:</p>
<ol>
<li>
<p>Maintain the style of passing a parameter formed by the bitwise-inclusive OR of flags to the initialization routines ( <a href=
"../functions/pthread_create.html"><i>pthread_create</i>()</a>, <a href=
"../functions/pthread_mutex_init.html"><i>pthread_mutex_init</i>()</a>, <a href=
"../functions/pthread_cond_init.html"><i>pthread_cond_init</i>()</a>). The parameter containing the flags should be an opaque type
for extensibility. If no flags are set in the parameter, then the objects are created with default characteristics. An
implementation may specify implementation-defined flag values and associated behavior.</p>
</li>
<li>
<p>If further specialization of mutexes and condition variables is necessary, implementations may specify additional procedures
that operate on the <b>pthread_mutex_t</b> and <b>pthread_cond_t</b> objects (instead of on attributes objects).</p>
</li>
</ol>
<p>The difficulties with this solution are:</p>
<ol>
<li>
<p>A bitmask is not opaque if bits have to be set into bitvector attributes objects using explicitly-coded bitwise-inclusive OR
operations. If the set of options exceeds an <b>int</b>, application programmers need to know the location of each bit. If bits are
set or read by encapsulation (that is, get and set functions), then the bitmask is merely an implementation of attributes objects
as currently defined and should not be exposed to the programmer.</p>
</li>
<li>
<p>Many attributes are not Boolean or very small integral values. For example, scheduling policy may be placed in 3-bit or 4-bit,
but priority requires 5-bit or more, thereby taking up at least 8 bits out of a possible 16 bits on machines with 16-bit integers.
Because of this, the bitmask can only reasonably control whether particular attributes are set or not, and it cannot serve as the
repository of the value itself. The value needs to be specified as a function parameter (which is non-extensible), or by setting a
structure field (which is non-opaque), or by get and set functions (making the bitmask a redundant addition to the attributes
objects).</p>
</li>
</ol>
<p>Stack size is defined as an optional attribute because the very notion of a stack is inherently machine-dependent. Some
implementations may not be able to change the size of the stack, for example, and others may not need to because stack pages may be
discontiguous and can be allocated and released on demand.</p>
<p>The attribute mechanism has been designed in large measure for extensibility. Future extensions to the attribute mechanism or to
any attributes object defined in this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 has to be done with care so as not to affect
binary-compatibility.</p>
<p>Attributes objects, even if allocated by means of dynamic allocation functions such as <a href=
"../functions/malloc.html"><i>malloc</i>()</a>, may have their size fixed at compile time. This means, for example, a <a href=
"../functions/pthread_create.html"><i>pthread_create</i>()</a> in an implementation with extensions to <b>pthread_attr_t</b> cannot
look beyond the area that the binary application assumes is valid. This suggests that implementations should maintain a size field
in the attributes object, as well as possibly version information, if extensions in different directions (possibly by different
vendors) are to be accommodated.</p>
</blockquote>
<h4><a name="tag_03_487_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_487_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="pthread_attr_getstackaddr.html"><i>pthread_attr_getstackaddr</i>()</a> , <a href=
"pthread_attr_getstacksize.html"><i>pthread_attr_getstacksize</i>()</a> , <a href=
"pthread_attr_getdetachstate.html"><i>pthread_attr_getdetachstate</i>()</a> , <a href=
"pthread_create.html"><i>pthread_create</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/pthread.h.html"><i>&lt;pthread.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_487_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 5. Included for alignment with the POSIX Threads Extension.</p>
</blockquote>
<h4><a name="tag_03_487_12"></a>Issue 6</h4>
<blockquote>
<p>The <i>pthread_attr_destroy</i>() and <i>pthread_attr_init</i>() functions are marked as part of the Threads option.</p>
<p>IEEE PASC Interpretation 1003.1 #107 is applied, noting that the effect of initializing an already initialized thread attributes
object is undefined.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>