7139 Sync mDNS with mDNSResponder-625.41.2
[unleashed.git] / usr / src / man / man3c / sem_init.3c
blobd91aa23763dcea7c446f5f9804af0d778ed03e27
1 '\" te
2 .\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at  http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text
7 .\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical
8 .\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\"  This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
11 .\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with
12 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH SEM_INIT 3C "Jul 9, 2009"
14 .SH NAME
15 sem_init \- initialize an unnamed semaphore
16 .SH SYNOPSIS
17 .LP
18 .nf
19 #include <semaphore.h>
21 \fBint\fR \fBsem_init\fR(\fBsem_t *\fR\fIsem\fR, \fBint\fR \fIpshared\fR, \fBunsigned int\fR \fIvalue\fR);
22 .fi
24 .SH DESCRIPTION
25 .sp
26 .LP
27 The \fBsem_init()\fR function is used to initialize the unnamed semaphore
28 referred to by \fIsem\fR. The value of the initialized semaphore is
29 \fIvalue\fR. Following a successful call to \fBsem_init()\fR, the semaphore may
30 be used in subsequent calls to \fBsem_wait\fR(3C), \fBsem_trywait\fR(3C),
31 \fBsem_post\fR(3C), and \fBsem_destroy\fR(3C). This semaphore remains usable
32 until the semaphore is destroyed.
33 .sp
34 .LP
35 If the \fIpshared\fR argument has a non-zero value, then the semaphore is
36 shared between processes; in this case, any process that can access the
37 semaphore \fIsem\fR can use \fIsem\fR for performing \fBsem_wait\fR(3C),
38 \fBsem_trywait\fR(3C), \fBsem_post\fR(3C), and \fBsem_destroy\fR(3C)
39 operations.
40 .sp
41 .LP
42 Only \fIsem\fR itself may be used for performing synchronization. The result of
43 referring to copies of \fIsem\fR in calls to \fBsem_wait\fR(3C),
44 \fBsem_trywait\fR(3C), \fBsem_post\fR(3C), and \fBsem_destroy\fR(3C), is
45 undefined.
46 .sp
47 .LP
48 If the \fIpshared\fR argument is zero, then the semaphore is shared between
49 threads of the process; any thread in this process can use \fIsem\fR for
50 performing \fBsem_wait\fR(3C), \fBsem_trywait\fR(3C), \fBsem_post\fR(3C), and
51 \fBsem_destroy\fR(3C) operations. The use of the semaphore by threads other
52 than those created in the same process is undefined.
53 .sp
54 .LP
55 Attempting to initialize an already initialized semaphore results in undefined
56 behavior.
57 .sp
58 .LP
59 The \fBsem_open\fR(3C) function is used with named semaphores.
60 .SH RETURN VALUES
61 .sp
62 .LP
63 Upon successful completion, the function initializes the semaphore in
64 \fIsem\fR. Otherwise, it returns \fB\(mi1\fR and sets \fBerrno\fR to indicate
65 the error.
66 .SH ERRORS
67 .sp
68 .LP
69 The \fBsem_init()\fR function will fail if:
70 .sp
71 .ne 2
72 .na
73 \fB\fBEINVAL\fR \fR
74 .ad
75 .RS 11n
76 The \fIvalue\fR argument exceeds  \fBSEM_VALUE_MAX\fR.
77 .RE
79 .sp
80 .ne 2
81 .na
82 \fB\fBENOSPC\fR \fR
83 .ad
84 .RS 11n
85 A resource required to initialize the semaphore has been exhausted, or the
86 resources have reached the limit on semaphores (\fBSEM_NSEMS_MAX\fR).
87 .RE
89 .sp
90 .ne 2
91 .na
92 \fB\fBENOSYS\fR \fR
93 .ad
94 .RS 11n
95 The \fBsem_init()\fR function is not supported by the system.
96 .RE
98 .sp
99 .ne 2
101 \fB\fBEPERM\fR \fR
103 .RS 11n
104 The process lacks the appropriate privileges to initialize the semaphore.
107 .SH ATTRIBUTES
110 See \fBattributes\fR(5) for descriptions of the following attributes:
115 box;
116 c | c
117 l | l .
118 ATTRIBUTE TYPE  ATTRIBUTE VALUE
120 Interface Stability     Committed
122 MT-Level        MT-Safe
124 Standard        See \fBstandards\fR(5).
127 .SH SEE ALSO
130 \fBsem_destroy\fR(3C), \fBsem_open\fR(3C), \fBsem_post\fR(3C),
131 \fBsem_wait\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)