164 lines
6.2 KiB
HTML
164 lines
6.2 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_getspecific</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="pthread_getspecific"></a> <a name="tag_03_532"></a><!-- pthread_getspecific -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_532_01"></a>NAME</h4>
|
|
|
|
<blockquote>pthread_getspecific, pthread_setspecific - thread-specific data management</blockquote>
|
|
|
|
<h4><a name="tag_03_532_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 <<a href="../basedefs/pthread.h.html">pthread.h</a>><br>
|
|
<br>
|
|
void *pthread_getspecific(pthread_key_t</tt> <i>key</i><tt>);<br>
|
|
int pthread_setspecific(pthread_key_t</tt> <i>key</i><tt>, const void *</tt><i>value</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_532_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>pthread_getspecific</i>() function shall return the value currently bound to the specified <i>key</i> on behalf of the
|
|
calling thread.</p>
|
|
|
|
<p>The <i>pthread_setspecific</i>() function shall associate a thread-specific <i>value</i> with a <i>key</i> obtained via a
|
|
previous call to <a href="../functions/pthread_key_create.html"><i>pthread_key_create</i>()</a>. Different threads may bind
|
|
different values to the same key. These values are typically pointers to blocks of dynamically allocated memory that have been
|
|
reserved for use by the calling thread.</p>
|
|
|
|
<p>The effect of calling <i>pthread_getspecific</i>() or <i>pthread_setspecific</i>() with a <i>key</i> value not obtained from <a
|
|
href="../functions/pthread_key_create.html"><i>pthread_key_create</i>()</a> or after <i>key</i> has been deleted with <a href=
|
|
"../functions/pthread_key_delete.html"><i>pthread_key_delete</i>()</a> is undefined.</p>
|
|
|
|
<p>Both <i>pthread_getspecific</i>() and <i>pthread_setspecific</i>() may be called from a thread-specific data destructor
|
|
function. A call to <i>pthread_getspecific</i>() for the thread-specific data key being destroyed shall return the value NULL,
|
|
unless the value is changed (after the destructor starts) by a call to <i>pthread_setspecific</i>(). Calling
|
|
<i>pthread_setspecific</i>() from a thread-specific data destructor routine may result either in lost storage (after at least
|
|
PTHREAD_DESTRUCTOR_ITERATIONS attempts at destruction) or in an infinite loop.</p>
|
|
|
|
<p>Both functions may be implemented as macros.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_532_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>pthread_getspecific</i>() function shall return the thread-specific data value associated with the given <i>key</i>. If
|
|
no thread-specific data value is associated with <i>key</i>, then the value NULL shall be returned.</p>
|
|
|
|
<p>If successful, the <i>pthread_setspecific</i>() function shall return zero; otherwise, an error number shall be returned to
|
|
indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_532_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>No errors are returned from <i>pthread_getspecific</i>().</p>
|
|
|
|
<p>The <i>pthread_setspecific</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[ENOMEM]</dt>
|
|
|
|
<dd>Insufficient memory exists to associate the value with the key.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>pthread_setspecific</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The key value is invalid.</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_532_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_532_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_532_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>Performance and ease-of-use of <i>pthread_getspecific</i>() are critical for functions that rely on maintaining state in
|
|
thread-specific data. Since no errors are required to be detected by it, and since the only error that could be detected is the use
|
|
of an invalid key, the function to <i>pthread_getspecific</i>() has been designed to favor speed and simplicity over error
|
|
reporting.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_532_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_532_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="pthread_key_create.html"><i>pthread_key_create</i>()</a> , the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/pthread.h.html"><i><pthread.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_532_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_532_12"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>pthread_getspecific</i>() and <i>pthread_setspecific</i>() functions are marked as part of the Threads option.</p>
|
|
|
|
<p>IEEE PASC Interpretation 1003.1c #3 (Part 6) is applied, updating the DESCRIPTION.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® 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>
|
|
|