pthread_spin_lock.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_SPIN_LOCK&quot;(P) manual page</TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)">
  7. <META NAME="CREATED" CONTENT="20050505;12202300">
  8. <META NAME="CHANGED" CONTENT="20050505;19302300">
  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_spin_lock, pthread_spin_trylock - lock a spin lock object
  18. (<B>ADVANCED REALTIME THREADS</B>)
  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>int pthread_spin_lock(pthread_spinlock_t *</B><I>lock</I><B>);
  24. <BR>int pthread_spin_trylock(pthread_spinlock_t *</B><I>lock</I><B>);
  25. </B>
  26. </P>
  27. <H2><A HREF="#toc2" NAME="sect2">Description</A></H2>
  28. <P>The <B>pthread_spin_lock</B> function shall lock the spin lock
  29. referenced by <I>lock</I>. The calling thread shall acquire the lock
  30. if it is not held by another thread. Otherwise, the thread shall spin
  31. (that is, shall not return from the <B>pthread_spin_lock</B> call)
  32. until the lock becomes available. The results are undefined if the
  33. calling thread holds the lock at the time the call is made.</P>
  34. <P><B>Pthreads-w32</B> supports single and multiple processor systems
  35. as well as process CPU affinity masking by checking the mask when the
  36. spin lock is initialized. If the process is using only a single
  37. processor at the time <A HREF="pthread_spin_init.html"><B>pthread_spin_init</B>(3)</A>
  38. is called then the spin lock is initialized as a PTHREAD_MUTEX_NORMAL
  39. mutex object. A thread that calls <B>pthread_spin_lock</B> will block
  40. rather than spin in this case. If the process CPU affinity mask is
  41. altered after the spin lock has been initialised, the spin lock is
  42. not modified, and may no longer be optimal for the number of CPUs
  43. available.</P>
  44. <P>The <B>pthread_spin_trylock</B> function shall lock the spin lock
  45. referenced by <I>lock</I> if it is not held by any thread. Otherwise,
  46. the function shall fail.
  47. </P>
  48. <P>The results are undefined if any of these functions is called with
  49. an uninitialized spin lock.
  50. </P>
  51. <H2><A HREF="#toc3" NAME="sect3">Return Value</A></H2>
  52. <P>Upon successful completion, these functions shall return zero;
  53. otherwise, an error number shall be returned to indicate the error.
  54. </P>
  55. <H2><A HREF="#toc4" NAME="sect4">Errors</A></H2>
  56. <P>These functions may fail if:
  57. </P>
  58. <DL>
  59. <DT><B>EINVAL</B>
  60. </DT><DD STYLE="margin-bottom: 0.5cm">
  61. The value specified by <I>lock</I> does not refer to an initialized
  62. spin lock object.
  63. </DD></DL>
  64. <P>
  65. The <B>pthread_spin_trylock</B> function shall fail if:
  66. </P>
  67. <DL>
  68. <DT><B>EBUSY</B>
  69. </DT><DD STYLE="margin-bottom: 0.5cm">
  70. A thread currently holds the lock.
  71. </DD></DL>
  72. <P>
  73. These functions shall not return an error code of [EINTR].
  74. </P>
  75. <P><I>The following sections are informative.</I>
  76. </P>
  77. <H2><A HREF="#toc5" NAME="sect5">Examples</A></H2>
  78. <P>None.
  79. </P>
  80. <H2><A HREF="#toc6" NAME="sect6">Application Usage</A></H2>
  81. <P>Applications using this function may be subject to priority
  82. inversion, as discussed in the Base Definitions volume of
  83. IEEE&nbsp;Std&nbsp;1003.1-2001, Section 3.285, Priority Inversion.
  84. </P>
  85. <H2><A HREF="#toc7" NAME="sect7">Rationale</A></H2>
  86. <P>None.
  87. </P>
  88. <H2><A HREF="#toc8" NAME="sect8">Future Directions</A></H2>
  89. <P>None.
  90. </P>
  91. <H2><A HREF="#toc9" NAME="sect9">See Also</A></H2>
  92. <P><A HREF="pthread_spin_init.html"><B>pthread_spin_destroy</B>(3)</A>
  93. <B>,</B> <A HREF="pthread_spin_unlock.html"><B>pthread_spin_unlock</B>(3)</A>
  94. <B>,</B> the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001,
  95. <I>&lt;pthread.h&gt;</I>
  96. </P>
  97. <H2><A HREF="#toc10" NAME="sect10">Copyright</A></H2>
  98. <P>Portions of this text are reprinted and reproduced in electronic
  99. form from IEEE Std 1003.1, 2003 Edition, Standard for Information
  100. Technology -- Portable Operating System Interface (POSIX), The Open
  101. Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the
  102. Institute of Electrical and Electronics Engineers, Inc and The Open
  103. Group. In the event of any discrepancy between this version and the
  104. original IEEE and The Open Group Standard, the original IEEE and The
  105. Open Group Standard is the referee document. The original Standard
  106. can be obtained online at <A HREF="http://www.opengroup.org/unix/online.html">http://www.opengroup.org/unix/online.html</A>
  107. .
  108. </P>
  109. <P>Modified by Ross Johnson for use with <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A>.</P>
  110. <HR>
  111. <P><A NAME="toc"></A><B>Table of Contents</B></P>
  112. <UL>
  113. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
  114. </P>
  115. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
  116. </P>
  117. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
  118. </P>
  119. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">Return
  120. Value</A>
  121. </P>
  122. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">Errors</A>
  123. </P>
  124. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">Examples</A>
  125. </P>
  126. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect6" NAME="toc6">Application
  127. Usage</A>
  128. </P>
  129. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect7" NAME="toc7">Rationale</A>
  130. </P>
  131. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect8" NAME="toc8">Future
  132. Directions</A>
  133. </P>
  134. <LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect9" NAME="toc9">See
  135. Also</A>
  136. </P>
  137. <LI><P><A HREF="#sect10" NAME="toc10">Copyright</A>
  138. </P>
  139. </UL>
  140. </BODY>
  141. </HTML>