1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
5
<TITLE>"PTHREAD_SPIN_LOCK"(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/ -->
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>)
20
<H2><A HREF="#toc1" NAME="sect1">Synopsis</A></H2>
21
<P><B>#include <pthread.h> </B>
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>);
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
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.
48
<P>The results are undefined if any of these functions is called with
49
an uninitialized spin lock.
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.
55
<H2><A HREF="#toc4" NAME="sect4">Errors</A></H2>
56
<P>These functions may fail if:
60
</DT><DD STYLE="margin-bottom: 0.5cm">
61
The value specified by <I>lock</I> does not refer to an initialized
65
The <B>pthread_spin_trylock</B> function shall fail if:
69
</DT><DD STYLE="margin-bottom: 0.5cm">
70
A thread currently holds the lock.
73
These functions shall not return an error code of [EINTR].
75
<P><I>The following sections are informative.</I>
77
<H2><A HREF="#toc5" NAME="sect5">Examples</A></H2>
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 Std 1003.1-2001, Section 3.285, Priority Inversion.
85
<H2><A HREF="#toc7" NAME="sect7">Rationale</A></H2>
88
<H2><A HREF="#toc8" NAME="sect8">Future Directions</A></H2>
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 Std 1003.1-2001,
95
<I><pthread.h></I>
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>
109
<P>Modified by Ross Johnson for use with <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A>.</P>
111
<P><A NAME="toc"></A><B>Table of Contents</B></P>
113
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
115
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
117
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
119
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">Return
122
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">Errors</A>
124
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">Examples</A>
126
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect6" NAME="toc6">Application
129
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect7" NAME="toc7">Rationale</A>
131
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect8" NAME="toc8">Future
134
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect9" NAME="toc9">See
137
<LI><P><A HREF="#sect10" NAME="toc10">Copyright</A>