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_DESTROY"(P) manual page</TITLE>
6
<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)">
7
<META NAME="CREATED" CONTENT="20050505;12074100">
8
<META NAME="CHANGED" CONTENT="20050505;19014200">
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_destroy, pthread_spin_init - destroy or initialize a
18
spin lock object (<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>pthread_spinlock_t</B> <I>lock</I> <B>=
24
PTHREAD_SPINLOCK_INITIALIZER;</B></P>
25
<P><B>int pthread_spin_destroy(pthread_spinlock_t *</B><I>lock</I><B>);
26
<BR>int pthread_spin_init(pthread_spinlock_t *</B><I>lock</I><B>, int</B>
27
<I>pshared</I><B>); </B>
29
<H2><A HREF="#toc2" NAME="sect2">Description</A></H2>
30
<P>The <B>pthread_spin_destroy</B> function shall destroy the spin
31
lock referenced by <I>lock</I> and release any resources used by the
32
lock. The effect of subsequent use of the lock is undefined until the
33
lock is reinitialized by another call to <B>pthread_spin_init</B> .
34
The results are undefined if <B>pthread_spin_destroy</B> is called
35
when a thread holds the lock, or if this function is called with an
36
uninitialized thread spin lock.
38
<P>The <B>pthread_spin_init</B> function shall allocate any resources
39
required to use the spin lock referenced by <I>lock</I> and
40
initialize the lock to an unlocked state.
42
<P><B>Pthreads-w32</B> supports single and multiple processor systems
43
as well as process CPU affinity masking by checking the mask when the
44
spin lock is initialized. If the process is using only a single
45
processor at the time <B>pthread_spin_init</B> is called then the
46
spin lock is initialized as a PTHREAD_MUTEX_NORMAL mutex object. A
47
thread that calls <A HREF="pthread_spin_lock.html"><B>pthread_spin_lock(3)</B></A>
48
will block rather than spin in this case. If the process CPU affinity
49
mask is altered after the spin lock has been initialised, the spin
50
lock is not modified, and may no longer be optimal for the number of
52
<P><B>Pthreads-w32</B> defines <B>_POSIX_THREAD_PROCESS_SHARED</B> in
53
pthread.h as -1 to indicate that these routines do not support the
54
<B>PTHREAD_PROCESS_SHARED</B> attribute. <B>pthread_spin_init</B>
55
will return the error <B>ENOTSUP</B> if the value of <I>pshared</I>
56
is not <B>PTHREAD_PROCESS_PRIVATE</B>.</P>
57
<P>The results are undefined if <B>pthread_spin_init</B> is called
58
specifying an already initialized spin lock. The results are
59
undefined if a spin lock is used without first being initialized.
61
<P>If the <B>pthread_spin_init</B> function fails, the lock is not
62
initialized and the contents of <I>lock</I> are undefined.
64
<P>Only the object referenced by <I>lock</I> may be used for
65
performing synchronization.
67
<P>The result of referring to copies of that object in calls to
68
<B>pthread_spin_destroy</B> , <A HREF="pthread_spin_lock.html"><B>pthread_spin_lock</B>(3)</A>
69
, <A HREF="pthread_spin_lock.html"><B>pthread_spin_trylock</B>(3)</A>,
70
or <A HREF="pthread_spin_unlock.html"><B>pthread_spin_unlock</B>(3)</A>
73
<P><B>Pthreads-w32</B> supports statically initialized spin locks
74
using <B>PTHREAD_SPINLOCK_INITIALIZER</B>. An application should
75
still call <B>pthread_spin_destroy</B> at some point to ensure that
76
any resources consumed by the spin lock are released.</P>
77
<H2><A HREF="#toc3" NAME="sect3">Return Value</A></H2>
78
<P>Upon successful completion, these functions shall return zero;
79
otherwise, an error number shall be returned to indicate the error.
81
<H2><A HREF="#toc4" NAME="sect4">Errors</A></H2>
82
<P>These functions may fail if:
87
The implementation has detected an attempt to initialize or destroy
88
a spin lock while it is in use (for example, while being used in a
89
<A HREF="pthread_spin_lock.html"><B>pthread_spin_lock</B>(3)</A>
90
call) by another thread.
93
</DT><DD STYLE="margin-bottom: 0.5cm">
94
The value specified by <I>lock</I> is invalid.
97
The <B>pthread_spin_init</B> function shall fail if:
102
The value of <I>pshared</I> is not <B>PTHREAD_PROCESS_PRIVATE</B>.</DD><DT>
104
</DT><DD STYLE="margin-bottom: 0.5cm">
105
Insufficient memory exists to initialize the lock.
108
These functions shall not return an error code of [EINTR].
110
<P><I>The following sections are informative.</I>
112
<H2><A HREF="#toc5" NAME="sect5">Examples</A></H2>
115
<H2><A HREF="#toc6" NAME="sect6">Application Usage</A></H2>
116
<P>The <B>pthread_spin_destroy</B> and <B>pthread_spin_init</B>
117
functions are part of the Spin Locks option and need not be provided
118
on all implementations.
120
<H2><A HREF="#toc7" NAME="sect7">Rationale</A></H2>
123
<H2><A HREF="#toc8" NAME="sect8">Future Directions</A></H2>
126
<H2><A HREF="#toc9" NAME="sect9">See Also</A></H2>
127
<P><A HREF="pthread_spin_lock.html"><B>pthread_spin_lock</B>(3)</A> <B>,</B>
128
<A HREF="pthread_spin_unlock.html"><B>pthread_spin_unlock</B>(3)</A>
129
<B>,</B> the Base Definitions volume of IEEE Std 1003.1-2001,
130
<I><pthread.h></I>
132
<H2><A HREF="#toc10" NAME="sect10">Copyright</A></H2>
133
<P>Portions of this text are reprinted and reproduced in electronic
134
form from IEEE Std 1003.1, 2003 Edition, Standard for Information
135
Technology -- Portable Operating System Interface (POSIX), The Open
136
Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the
137
Institute of Electrical and Electronics Engineers, Inc and The Open
138
Group. In the event of any discrepancy between this version and the
139
original IEEE and The Open Group Standard, the original IEEE and The
140
Open Group Standard is the referee document. The original Standard
141
can be obtained online at <A HREF="http://www.opengroup.org/unix/online.html">http://www.opengroup.org/unix/online.html</A>
144
<P>Modified by Ross Johnson for use with <A HREF="http://sources.redhat.com/pthreads-win32">Pthreads-w32</A>.</P>
146
<P><A NAME="toc"></A><B>Table of Contents</B></P>
148
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect0" NAME="toc0">Name</A>
150
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect1" NAME="toc1">Synopsis</A>
152
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect2" NAME="toc2">Description</A>
154
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect3" NAME="toc3">Return
157
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect4" NAME="toc4">Errors</A>
159
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect5" NAME="toc5">Examples</A>
161
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect6" NAME="toc6">Application
164
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect7" NAME="toc7">Rationale</A>
166
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect8" NAME="toc8">Future
169
<LI><P STYLE="margin-bottom: 0cm"><A HREF="#sect9" NAME="toc9">See
172
<LI><P><A HREF="#sect10" NAME="toc10">Copyright</A>