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

📄 pthread_mutexattr_settype.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>pthread_mutexattr_settype</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_007_1558">&nbsp;</a>NAME</h4><blockquote>pthread_mutexattr_gettype, pthread_mutexattr_settype- get or set a mutex type</blockquote><h4><a name = "tag_000_007_1559">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="pthread.h.html">pthread.h</a>&gt;int pthread_mutexattr_gettype(const pthread_mutexattr_t <i>*attr</i>, int <i>*type</i>);int pthread_mutexattr_settype(pthread_mutexattr_t <i>*attr</i>, int <i>type</i>);</code></pre></blockquote><h4><a name = "tag_000_007_1560">&nbsp;</a>DESCRIPTION</h4><blockquote>The <i>pthread_mutexattr_gettype()</i>and <i>pthread_mutexattr_settype()</i>functions respectively get and set the mutex <i>type</i> attribute.This attribute is set in the <i>type</i> parameterto these functions. The default value of the <i>type</i>attribute is PTHREAD_MUTEX_DEFAULT.<p>The type of mutex is contained in the <i>type</i> attribute of themutex attributes. Valid mutex types include:<dl compact><dt>PTHREAD_MUTEX_NORMAL<dd>This type of mutex does not detect deadlock. A threadattempting to relock this mutex without first unlocking itwill deadlock.  Attempting to unlock amutex locked by a different thread results in undefined behaviour.Attempting to unlock an unlockedmutex results in undefined behaviour.<dt>PTHREAD_MUTEX_ERRORCHECK<dd>This type of mutex provides error checking.  A threadattempting to relock this mutex without first unlocking itwill return with an error.A thread attempting to unlock a mutex which anotherthread has locked will return with an error.A thread attempting to unlock an unlocked mutex willreturn with an error. <dt>PTHREAD_MUTEX_RECURSIVE<dd>A thread attempting to relock this mutex without firstunlocking it will succeed in locking the mutex. The relockingdeadlock which can occur withmutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this typeof mutex. Multiplelocks of this mutex require the same number of unlocks to releasethe mutex before another threadcan acquire the mutex.A thread attempting to unlock a mutex which another thread haslocked will return with an error. A thread attempting to unlock an unlocked mutex will return with an error.<dt>PTHREAD_MUTEX_DEFAULT<dd>Attempting to recursively lock a mutex of this type results inundefined behaviour. Attempting to unlock a mutex of this type whichwas not locked by the callingthread results in undefined behaviour. Attempting to unlock a mutexof this type which is not locked results in undefined behaviour. An implementation is allowed to map this mutex to one of theother mutex types.</dl></blockquote><h4><a name = "tag_000_007_1561">&nbsp;</a>RETURN VALUE</h4><blockquote>If successful, the <i>pthread_mutexattr_settype()</i>function returns zero.  Otherwise, an error number isreturned to indicate the error.<p>Upon successful completion, the <i>pthread_mutexattr_gettype()</i>function returns zero and stores 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 is returned to indicatethe error.<br></blockquote><h4><a name = "tag_000_007_1562">&nbsp;</a>ERRORS</h4><blockquote>The<i>pthread_mutexattr_gettype()</i>and <i>pthread_mutexattr_settype()</i>functions will fail if:<dl compact><dt>[EINVAL]<dd>The value <i>type</i> is invalid.</dl><p>The<i>pthread_mutexattr_gettype()</i>and<i>pthread_mutexattr_settype()</i>functions may fail if:<dl compact><dt>[EINVAL]<dd>The value specified by <i>attr</i> is invalid.</dl></blockquote><h4><a name = "tag_000_007_1563">&nbsp;</a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1564">&nbsp;</a>APPLICATION USAGE</h4><blockquote>It is advised that an application should not usea PTHREAD_MUTEX_RECURSIVE mutex with condition variablesbecause the implicit unlock performed for a <i><a href="pthread_cond_wait.html">pthread_cond_wait()</a></i>or <i><a href="pthread_cond_timedwait.html">pthread_cond_timedwait()</a></i>may not actually release themutex (if it had been locked multiple times). If this happens,no other thread can satisfy the condition of the predicate.</blockquote><h4><a name = "tag_000_007_1565">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1566">&nbsp;</a>SEE ALSO</h4><blockquote><i><a href="pthread_cond_wait.html">pthread_cond_wait()</a></i>,<i><a href="pthread_cond_timedwait.html">pthread_cond_timedwait()</a></i>,<i><a href="pthread.h.html">&lt;pthread.h&gt;</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX &reg; is a registered Trademark of The Open Group.<br>Copyright &copy; 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>

⌨️ 快捷键说明

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