📄 pthread_rwlock_init.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>pthread_rwlock_init</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_1585"> </a>NAME</h4><blockquote>pthread_rwlock_init, pthread_rwlock_destroy- initialise or destroy a read-write lock object</blockquote><h4><a name = "tag_000_007_1586"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="pthread.h.html">pthread.h</a>> int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t <i>*attr</i>);int pthread_rwlock_destroy(pthread_rwlock_t <i>*rwlock</i>);pthread_rwlock_t <i>rwlock</i>=PTHREAD_RWLOCK_INITIALIZER;</code></pre></blockquote><h4><a name = "tag_000_007_1587"> </a>DESCRIPTION</h4><blockquote>The <i>pthread_rwlock_init()</i>function initialises the read-write lock referenced by <i>rwlock</i> with the attributes referenced by <i>attr</i>. If <i>attr</i> is NULL, thedefault read-write lock attributes are used; the effect is the same as passing the address of a default read-write lock attributes object. Once initialised, the lock can be used any number of times without being re-initialised. Upon successful initialisation, the state of the read-write lock becomes initialised and unlocked. Results are undefined if <i>pthread_rwlock_init()</i>is called specifying an already initialised read-write lock. Results are undefined if a read-write lock is used without first being initialised.<p>If the <i>pthread_rwlock_init()</i>function fails, <i>rwlock</i> is not initialised and the contents of <i>rwlock</i> are undefined.<p>The <i>pthread_rwlock_destroy()</i>function destroys the read-write lock object referenced by <i>rwlock</i>and releases any resources used by the lock. The effect of subsequent use of the lock is undefined until the lock is re-initialised by another call to <i>pthread_rwlock_init()</i>.An implementation may cause <i>pthread_rwlock_destroy()</i>to set the object referenced by <i>rwlock</i> to an invalid value. Results are undefined if <i>pthread_rwlock_destroy()</i>is called when any thread holds <i>rwlock</i>. Attempting to destroy an uninitialised read-write lock results in undefined behaviour. A destroyed read-write lock object can be re-initialised using <i>pthread_rwlock_init()</i>;the results of otherwise referencing the read-write lock object after it has been destroyed are undefined. <p>In cases where default read-write lock attributes are appropriate, themacro PTHREAD_RWLOCK_INITIALIZER can be used to initialise read-write locksthat are statically allocated. The effect is equivalent to dynamic initialisation by a call to <i>pthread_rwlock_init()</i>with the parameter <i>attr</i> specified as NULL, except that no error checks are performed. </blockquote><h4><a name = "tag_000_007_1588"> </a>RETURN VALUE</h4><blockquote>If successful, the <i>pthread_rwlock_init()</i>and <i>pthread_rwlock_destroy()</i>functions return zero. Otherwise, an error number is returned to indicate the error. The [EBUSY] and [EINVAL] error checks, if implemented, will act as if they were performed immediately at the beginning of processing for the function and caused an error return prior to modifying the state of the read-write lock specified by<i>rwlock</i>. </blockquote><h4><a name = "tag_000_007_1589"> </a>ERRORS</h4><blockquote>The<i>pthread_rwlock_init()</i>function will fail if:<dl compact><dt>[EAGAIN]<dd>The system lacked the necessary resources (other than memory)to initialise another read-write lock.<dt>[ENOMEM]<dd>Insufficient memory exists to initialise the read-write lock.<dt>[EPERM]<dd>The caller does not have the privilege to perform the operation.</dl><p>The<i>pthread_rwlock_init()</i>function may fail if:<dl compact><dt>[EBUSY]<dd>The implementation has detected an attempt to re-initialise theobject referenced by <i>rwlock</i>, a previously initialised butnot yet destroyed read-write lock.<dt>[EINVAL]<dd>The value specified by <i>attr</i> is invalid.</dl><p>The<i>pthread_rwlock_destroy()</i>function may fail if:<dl compact><dt>[EBUSY]<dd>The implementation has detected an attempt to destroy theobject referenced by <i>rwlock</i> while it is locked.<dt>[EINVAL]<dd>The value specified by <i>attr</i> is invalid.</dl></blockquote><h4><a name = "tag_000_007_1590"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1591"> </a>APPLICATION USAGE</h4><blockquote>Similar functions are being developed by IEEE PASC.In keeping with its objective of ensuring that CAESpecifications are fully aligned with formal standards, The Open Groupintends to add any new interfaces adopted by an official IEEE standardin this area.</blockquote><h4><a name = "tag_000_007_1592"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1593"> </a>SEE ALSO</h4><blockquote><i><a href="pthread.h.html"><pthread.h></a></i>,<i><a href="pthread_rwlock_rdlock.html">pthread_rwlock_rdlock()</a></i>,<i><a href="pthread_rwlock_wrlock.html">pthread_rwlock_wrlock()</a></i>,<i><a href="pthread_rwlockattr_init.html">pthread_rwlockattr_init()</a></i>,<i><a href="pthread_rwlock_unlock.html">pthread_rwlock_unlock()</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 + -