pthread_rwlock_init.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
  5. <TITLE>&quot;PTHREAD_RWLOCK_DESTROY&quot;(P) manual page</TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)">
  7. <META NAME="CREATED" CONTENT="20050505;10211800">
  8. <META NAME="CHANGED" CONTENT="20050505;18563400">
  9. <!-- manual page source format generated by PolyglotMan v3.2, -->
  10. <!-- available at http://polyglotman.sourceforge.net/ -->
  11. </HEAD>
  12. <BODY LANG="en-GB" BGCOLOR="#ffffff" DIR="LTR">
  13. <H4>POSIX Threads for Windows – REFERENCE - <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A></H4>
  14. <P><A HREF="index.html">Reference Index</A></P>
  15. <P><A HREF="#toc">Table of Contents</A></P>
  16. <H2><A HREF="#toc0" NAME="sect0">Name</A></H2>
  17. <P>pthread_rwlock_destroy, pthread_rwlock_init - destroy and
  18. initialize a read-write lock object
  19. </P>
  20. <H2><A HREF="#toc1" NAME="sect1">Synopsis</A></H2>
  21. <P><B>#include &lt;pthread.h&gt; </B>
  22. </P>
  23. <P><B>pthread_wrlock_t </B><I>rwlock</I> <B>=
  24. PTHREAD_RWLOCK_INITIALIZER;</B></P>
  25. <P><B>int pthread_rwlock_destroy(pthread_rwlock_t *</B><I>rwlock</I><B>);
  26. <BR>int pthread_rwlock_init(pthread_rwlock_t *restrict</B> <I>rwlock</I><B>,
  27. const pthread_rwlockattr_t *restrict</B> <I>attr</I><B>); </B>
  28. </P>
  29. <H2><A HREF="#toc2" NAME="sect2">Description</A></H2>
  30. <P>The <B>pthread_rwlock_destroy</B> function shall destroy the
  31. read-write lock object referenced by <I>rwlock</I> and release any
  32. resources used by the lock. The effect of subsequent use of the lock
  33. is undefined until the lock is reinitialized by another call to
  34. <B>pthread_rwlock_init</B>. An implementation may cause
  35. <B>pthread_rwlock_destroy</B> to set the object referenced by <I>rwlock</I>
  36. to an invalid value. Results are undefined if <B>pthread_rwlock_destroy</B>
  37. is called when any thread holds <I>rwlock</I>. Attempting to destroy
  38. an uninitialized read-write lock results in undefined behavior.
  39. </P>
  40. <P>The <B>pthread_rwlock_init</B> function shall allocate any
  41. resources required to use the read-write lock referenced by <I>rwlock</I>
  42. and initializes the lock to an unlocked state with attributes
  43. referenced by <I>attr</I>. If <I>attr</I> is NULL, the default
  44. read-write lock attributes shall be used; the effect is the same as
  45. passing the address of a default read-write lock attributes object.
  46. Once initialized, the lock can be used any number of times without
  47. being reinitialized. Results are undefined if <B>pthread_rwlock_init</B>
  48. is called specifying an already initialized read-write lock. Results
  49. are undefined if a read-write lock is used without first being
  50. initialized.
  51. </P>
  52. <P>If the <B>pthread_rwlock_init</B> function fails, <I>rwlock</I>
  53. shall not be initialized and the contents of <I>rwlock</I> are
  54. undefined.
  55. </P>
  56. <P><B>Pthreads-w32</B> supports statically initialized <I>rwlock</I>
  57. objects using <B>PTHREAD_RWLOCK_INITIALIZER</B>. <SPAN STYLE="font-weight: medium">
  58. An application should still call <B>pthread_rwlock_destroy</B> at
  59. some point to ensure that any resources consumed by the read/write
  60. lock are released.</SPAN></P>
  61. <P>Only the object referenced by <I>rwlock</I> may be used for
  62. performing synchronization. The result of referring to copies of that
  63. object in calls to <B>pthread_rwlock_destroy</B> ,
  64. <B>pthread_rwlock_rdlock</B> , <B>pthread_rwlock_timedrdlock</B> ,
  65. <B>pthread_rwlock_timedwrlock</B> , <B>pthread_rwlock_tryrdlock</B> ,
  66. <B>pthread_rwlock_trywrlock</B> , <B>pthread_rwlock_unlock</B> , or
  67. <B>pthread_rwlock_wrlock</B> is undefined.
  68. </P>
  69. <P><B>Pthreads-w32</B> defines <B>_POSIX_READER_WRITER_LOCKS</B> in
  70. pthread.h as 200112L to indicate that the reader/writer routines are
  71. implemented and may be used.</P>
  72. <H2><A HREF="#toc3" NAME="sect3">Return Value</A></H2>
  73. <P>If successful, the <B>pthread_rwlock_destroy</B> and
  74. <B>pthread_rwlock_init</B> functions shall return zero; otherwise, an
  75. error number shall be returned to indicate the error.
  76. </P>
  77. <P>The [EBUSY] and [EINVAL] error checks, if implemented, act as if
  78. they were performed immediately at the beginning of processing for
  79. the function and caused an error return prior to modifying the state
  80. of the read-write lock specified by <I>rwlock</I>.
  81. </P>
  82. <H2><A HREF="#toc4" NAME="sect4">Errors</A></H2>
  83. <P>The <B>pthread_rwlock_destroy</B> function may fail if:
  84. </P>
  85. <DL>
  86. <DT><B>EBUSY</B>
  87. </DT><DD>
  88. The implementation has detected an attempt to destroy the object
  89. referenced by <I>rwlock</I> while it is locked.
  90. </DD><DT>
  91. <B>EINVAL</B>
  92. </DT><DD STYLE="margin-bottom: 0.5cm">
  93. The value specified by <I>rwlock</I> is invalid.
  94. </DD></DL>
  95. <P>
  96. The <B>pthread_rwlock_init</B> function shall fail if:
  97. </P>
  98. <DL>
  99. <DT><B>EAGAIN</B>
  100. </DT><DD>
  101. The system lacked the necessary resources (other than memory) to
  102. initialize another read-write lock.
  103. </DD><DT>
  104. <B>ENOMEM</B>
  105. </DT><DD>
  106. Insufficient memory exists to initialize the read-write lock.
  107. </DD><DD STYLE="margin-left: 0cm; margin-bottom: 0.5cm">
  108. <BR><BR>
  109. </DD></DL>
  110. <P>
  111. The <B>pthread_rwlock_init</B> function may fail if:
  112. </P>
  113. <DL>
  114. <DT><B>EINVAL</B>
  115. </DT><DD STYLE="margin-bottom: 0.5cm">
  116. The value specified by <I>attr</I> is invalid.
  117. </DD></DL>
  118. <P>
  119. These functions shall not return an error code of [EINTR].
  120. </P>
  121. <P><I>The following sections are informative.</I>
  122. </P>
  123. <H2><A HREF="#toc5" NAME="sect5">Examples</A></H2>
  124. <P>None.
  125. </P>
  126. <H2><A HREF="#toc6" NAME="sect6">Application Usage</A></H2>
  127. <P>Applications using these and related read-write lock functions may
  128. be subject to priority inversion, as discussed in the Base
  129. Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, Section 3.285,
  130. Priority Inversion.
  131. </P>
  132. <H2><A HREF="#toc7" NAME="sect7">Rationale</A></H2>
  133. <P>None.
  134. </P>
  135. <H2><A HREF="#toc8" NAME="sect8">Future Directions</A></H2>
  136. <P>None.
  137. </P>
  138. <H2><A HREF="#toc9" NAME="sect9">See Also</A></H2>
  139. <P><A HREF="pthread_rwlock_rdlock.html"><B>pthread_rwlock_rdlock</B>(3)</A>
  140. <B>,</B> <A HREF="pthread_rwlock_timedrdlock.html"><B>pthread_rwlock_timedrdlock</B>(3)</A>
  141. <B>,</B> <A HREF="pthread_rwlock_timedwrlock.html"><B>pthread_rwlock_timedwrlock</B>(3)</A>
  142. <B>,</B> <A HREF="pthread_rwlock_rdlock.html"><B>pthread_rwlock_tryrdlock</B>(3)</A>
  143. <B>,</B> <A HREF="pthread_rwlock_wrlock.html"><B>pthread_rwlock_trywrlock</B>(3)</A>
  144. <B>,</B> <A HREF="pthread_rwlock_unlock.html"><B>pthread_rwlock_unlock</B>(3)</A>
  145. <B>,</B> <A HREF="pthread_rwlock_wrlock.html"><B>pthread_rwlock_wrlock</B>(3)</A>
  146. <B>,</B> the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001,
  147. <I>&lt;pthread.h&gt;</I>
  148. </P>
  149. <H2><A HREF="#toc10" NAME="sect10">Copyright</A></H2>
  150. <P>Portions of this text are reprinted and reproduced in electronic
  151. form from IEEE Std 1003.1, 2003 Edition, Standard for Information
  152. Technology -- Portable Operating System Interface (POSIX), The Open
  153. Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the
  154. Institute of Electrical and Electronics Engineers, Inc and The Open
  155. Group. In the event of any discrepancy between this version and the
  156. original IEEE and The Open Group Standard, the original IEEE and The
  157. Open Group Standard is the referee document. The original Standard
  158. can be obtained online at <A HREF="http://www.opengroup.org/unix/online.html">http://www.opengroup.org/unix/online.html</A>
  159. .
  160. </P>
  161. <P>Modified by Ross Johnson for use with <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A>.</P>
  162. <HR>
  163. <P><A NAME="toc"></A><B>Table of Contents</B></P>
  164. <UL>
  165. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
  166. </P>
  167. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
  168. </P>
  169. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
  170. </P>
  171. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">Return
  172. Value</A>
  173. </P>
  174. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">Errors</A>
  175. </P>
  176. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">Examples</A>
  177. </P>
  178. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect6" NAME="toc6">Application
  179. Usage</A>
  180. </P>
  181. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect7" NAME="toc7">Rationale</A>
  182. </P>
  183. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect8" NAME="toc8">Future
  184. Directions</A>
  185. </P>
  186. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect9" NAME="toc9">See
  187. Also</A>
  188. </P>
  189. <LI><P><A HREF="#sect10" NAME="toc10">Copyright</A>
  190. </P>
  191. </UL>
  192. </BODY>
  193. </HTML>