nightly: remove unused BINARCHIVE
[unleashed.git] / share / man / man3c / pthread_mutex_init.3c
blobe45160feb0f088958d1564bdd1f3540685c5e592
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1991, 1992, 1994, The X/Open Company Ltd.
44 .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
45 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
46 .\"
47 .TH PTHREAD_MUTEX_INIT 3C "Nov 11, 2008"
48 .SH NAME
49 pthread_mutex_init, pthread_mutex_destroy \- initialize or destroy a mutex
50 .SH SYNOPSIS
51 .LP
52 .nf
53 cc -mt [ \fIflag\fR... ] \fIfile\fR... -lpthread [ \fIlibrary\fR... ]
54 #include <pthread.h>
56 \fBint\fR \fBpthread_mutex_init\fR(\fBpthread_mutex_t *restrict\fR \fImutex\fR,
57      \fBconst pthread_mutexattr_t *restrict\fR \fIattr\fR);
58 .fi
60 .LP
61 .nf
62 \fBint\fR \fBpthread_mutex_destroy\fR(\fBpthread_mutex_t *\fR\fImutex\fR);
63 .fi
65 .LP
66 .nf
67 \fBpthread_mutex_t\fR \fImutex\fR= \fBPTHREAD_MUTEX_INITIALIZER\fR;
68 .fi
70 .SH DESCRIPTION
71 .sp
72 .LP
73 The \fBpthread_mutex_init()\fR function initializes the mutex referenced by
74 \fImutex\fR with attributes specified by \fIattr\fR. If \fIattr\fR is
75 \fINULL\fR, the default mutex attributes are used; the effect is the same as
76 passing the address of a default mutex attributes object. Upon successful
77 initialization, the state of the mutex becomes initialized and unlocked.
78 .sp
79 .LP
80 Except for robust mutexes, attempting to initialize an already initialized
81 mutex results in undefined behavior.
82 .sp
83 .LP
84 The \fBpthread_mutex_destroy()\fR function destroys the mutex object referenced
85 by \fImutex\fR; the mutex object becomes, in effect, uninitialized. A destroyed
86 mutex object can be re-initialized using \fBpthread_mutex_init()\fR; the
87 results of otherwise referencing the object after it has been destroyed are
88 undefined.
89 .sp
90 .LP
91 It is safe to destroy an initialized mutex that is unlocked. Attempting to
92 destroy a locked mutex results in undefined behavior.
93 .sp
94 .LP
95 In cases where default mutex attributes are appropriate, the macro
96 \fBPTHREAD_MUTEX_INITIALIZER\fR can be used to initialize mutexes that are
97 statically allocated. The effect is equivalent to dynamic initialization by a
98 call to \fBpthread_mutex_init()\fR with parameter \fIattr\fR specified as
99 \fINULL\fR, except that no error checks are performed.
100 .SH RETURN VALUES
103 If successful, the \fBpthread_mutex_init()\fR and \fBpthread_mutex_destroy()\fR
104 functions return  \fB0\fR. Otherwise, an error number is returned to indicate
105 the error.
106 .SH ERRORS
109 The \fBpthread_mutex_init()\fR function will fail if:
111 .ne 2
113 \fB\fBEAGAIN\fR\fR
115 .RS 10n
116 The system lacked the necessary resources (other than memory) to initialize
117 another mutex.
121 .ne 2
123 \fB\fBEBUSY\fR\fR
125 .RS 10n
126 An attempt was detected to  re-initialize a robust mutex previously initialized
127 but not yet destroyed. See \fBpthread_mutexattr_setrobust\fR(3C).
131 .ne 2
133 \fB\fBEINVAL\fR\fR
135 .RS 10n
136 An attempt was detected to re-initialize a robust mutex previously initialized
137 with a different set of attributes. See \fBpthread_mutexattr_setrobust\fR(3C).
141 .ne 2
143 \fB\fBENOMEM\fR\fR
145 .RS 10n
146 Insufficient memory exists to initialize the mutex.
150 .ne 2
152 \fB\fBEPERM\fR\fR
154 .RS 10n
155 The caller does not have the privilege to perform the operation.
160 The \fBpthread_mutex_init()\fR function may fail if:
162 .ne 2
164 \fB\fBEBUSY\fR\fR
166 .RS 10n
167 An attempt was detected to re-initialize the object referenced by \fImutex\fR,
168 a mutex previously initialized but not yet destroyed.
172 .ne 2
174 \fB\fBEINVAL\fR\fR
176 .RS 10n
177 The value specified by \fIattr\fR or \fImutex\fR is invalid.
182 The \fBpthread_mutex_destroy()\fR function may fail if:
184 .ne 2
186 \fB\fBEBUSY\fR\fR
188 .RS 10n
189 An attempt was detected to destroy the object referenced by \fImutex\fR while
190 it is locked or referenced (for example, while being used in a
191 \fBpthread_cond_wait\fR(3C) or \fBpthread_cond_timedwait\fR(3C)) by another
192 thread.
196 .ne 2
198 \fB\fBEINVAL\fR\fR
200 .RS 10n
201 The value specified by \fImutex\fR is invalid.
204 .SH ATTRIBUTES
207 See \fBattributes\fR(5) for descriptions of the following attributes:
212 box;
213 c | c
214 l | l .
215 ATTRIBUTE TYPE  ATTRIBUTE VALUE
217 Interface Stability     Standard
219 MT-Level        MT-Safe
222 .SH SEE ALSO
225 \fBpthread_cond_wait\fR(3C), \fBpthread_mutex_lock\fR(3C),
226 \fBpthread_mutexattr_setprioceiling\fR(3C),
227 \fBpthread_mutexattr_setprotocol\fR(3C),
228 \fBpthread_mutexattr_setpshared\fR(3C), \fBpthread_mutexattr_setrobust\fR(3C),
229 \fBpthread_mutexattr_settype\fR(3C), \fBattributes\fR(5), \fBmutex\fR(5),
230 \fBstandards\fR(5)