⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthread_mutexattr_settype.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 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-2003 The Open Group, All Rights Reserved --><title>pthread_mutexattr_gettype</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="pthread_mutexattr_gettype"></a> <a name="tag_03_548"></a><!-- pthread_mutexattr_gettype --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_548_01"></a>NAME</h4><blockquote>pthread_mutexattr_gettype, pthread_mutexattr_settype - get and set the mutex type attribute</blockquote><h4><a name="tag_03_548_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</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_mutexattr_gettype(const pthread_mutexattr_t *restrict</tt> <i>attr</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int *restrict</tt> <i>type</i><tt>);<br> int pthread_mutexattr_settype(pthread_mutexattr_t</tt> <i>*attr</i><tt>, int</tt> <i>type</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_548_03"></a>DESCRIPTION</h4><blockquote><p>The <i>pthread_mutexattr_gettype</i>() and <i>pthread_mutexattr_settype</i>() functions, respectively, shall get and set themutex <i>type</i> attribute. This attribute is set in the <i>type</i> parameter to these functions. The default value of the<i>type</i> attribute is PTHREAD_MUTEX_DEFAULT.</p><p>The type of mutex is contained in the <i>type</i> attribute of the mutex attributes. Valid mutex types include:</p><dl compact><dt>PTHREAD_MUTEX_NORMAL</dt><dd><br>This type of mutex does not detect deadlock. A thread attempting to relock this mutex without first unlocking it shall deadlock.Attempting to unlock a mutex locked by a different thread results in undefined behavior. Attempting to unlock an unlocked mutexresults in undefined behavior.</dd><dt>PTHREAD_MUTEX_ERRORCHECK</dt><dd><br>This type of mutex provides error checking. A thread attempting to relock this mutex without first unlocking it shall return withan error. A thread attempting to unlock a mutex which another thread has locked shall return with an error. A thread attempting tounlock an unlocked mutex shall return with an error.</dd><dt>PTHREAD_MUTEX_RECURSIVE</dt><dd><br>A thread attempting to relock this mutex without first unlocking it shall succeed in locking the mutex. The relocking deadlockwhich can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex. Multiple locks of this mutex shallrequire the same number of unlocks to release the mutex before another thread can acquire the mutex. A thread attempting to unlocka mutex which another thread has locked shall return with an error. A thread attempting to unlock an unlocked mutex shall returnwith an error.</dd><dt>PTHREAD_MUTEX_DEFAULT</dt><dd><br>Attempting to recursively lock a mutex of this type results in undefined behavior. Attempting to unlock a mutex of this type whichwas not locked by the calling thread results in undefined behavior. Attempting to unlock a mutex of this type which is not lockedresults in undefined behavior. An implementation may map this mutex to one of the other mutex types.</dd></dl></blockquote><h4><a name="tag_03_548_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, the <i>pthread_mutexattr_gettype</i>() function shall return zero and store the value of the<i>type</i> attribute of <i>attr</i> into the object referenced by the <i>type</i> parameter. Otherwise, an error shall be returnedto indicate the error.</p><p>If successful, the <i>pthread_mutexattr_settype</i>() function shall return zero; otherwise, an error number shall be returnedto indicate the error.</p></blockquote><h4><a name="tag_03_548_05"></a>ERRORS</h4><blockquote><p>The <i>pthread_mutexattr_settype</i>() function shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The value <i>type</i> is invalid.</dd></dl><p>The <i>pthread_mutexattr_gettype</i>() and <i>pthread_mutexattr_settype</i>() functions may fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The value specified by <i>attr</i> 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_548_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_548_07"></a>APPLICATION USAGE</h4><blockquote><p>It is advised that an application should not use a PTHREAD_MUTEX_RECURSIVE mutex with condition variables because the implicitunlock performed for a <a href="../functions/pthread_cond_timedwait.html"><i>pthread_cond_timedwait</i>()</a> or <a href="../functions/pthread_cond_wait.html"><i>pthread_cond_wait</i>()</a> may not actually release the mutex (if it had been lockedmultiple times). If this happens, no other thread can satisfy the condition of the predicate.</p></blockquote><h4><a name="tag_03_548_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_548_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_548_10"></a>SEE ALSO</h4><blockquote><p><a href="pthread_cond_timedwait.html"><i>pthread_cond_timedwait</i>()</a> , the Base Definitions volume ofIEEE&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_548_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 5.</p></blockquote><h4><a name="tag_03_548_12"></a>Issue 6</h4><blockquote><p>The Open Group Corrigendum U033/3 is applied. The SYNOPSIS for <i>pthread_mutexattr_gettype</i>() is updated so that the firstargument is of type <b>const pthread_mutexattr_t *</b>.</p><p>The <b>restrict</b> keyword is added to the <i>pthread_mutexattr_gettype</i>() prototype for alignment with theISO/IEC&nbsp;9899:1999 standard.</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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -