📄 pthread_mutexattr_settype.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 ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_007_1558"> </a>NAME</h4><blockquote>pthread_mutexattr_gettype, pthread_mutexattr_settype- get or set a mutex type</blockquote><h4><a name = "tag_000_007_1559"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="pthread.h.html">pthread.h</a>>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"> </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"> </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"> </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"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1564"> </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"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1566"> </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"><pthread.h></a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 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 + -