xref: /freebsd/lib/libc/gen/sem_init.3 (revision 26b6c45a92c8eae91cad4a7ce8935e08d2e5d368)
1c5e7e03aSRuslan Ermilov.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
2b0a1b4f8SJason Evans.\" All rights reserved.
3b0a1b4f8SJason Evans.\"
4b0a1b4f8SJason Evans.\" Redistribution and use in source and binary forms, with or without
5b0a1b4f8SJason Evans.\" modification, are permitted provided that the following conditions
6b0a1b4f8SJason Evans.\" are met:
7b0a1b4f8SJason Evans.\" 1. Redistributions of source code must retain the above copyright
8b0a1b4f8SJason Evans.\"    notice(s), this list of conditions and the following disclaimer as
9b0a1b4f8SJason Evans.\"    the first lines of this file unmodified other than the possible
10b0a1b4f8SJason Evans.\"    addition of one or more copyright notices.
11b0a1b4f8SJason Evans.\" 2. Redistributions in binary form must reproduce the above copyright
12b0a1b4f8SJason Evans.\"    notice(s), this list of conditions and the following disclaimer in
13b0a1b4f8SJason Evans.\"    the documentation and/or other materials provided with the
14b0a1b4f8SJason Evans.\"    distribution.
15b0a1b4f8SJason Evans.\"
16b0a1b4f8SJason Evans.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17b0a1b4f8SJason Evans.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b0a1b4f8SJason Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19b0a1b4f8SJason Evans.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20b0a1b4f8SJason Evans.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21b0a1b4f8SJason Evans.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22b0a1b4f8SJason Evans.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23b0a1b4f8SJason Evans.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24b0a1b4f8SJason Evans.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25b0a1b4f8SJason Evans.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26b0a1b4f8SJason Evans.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27b0a1b4f8SJason Evans.\"
28b0a1b4f8SJason Evans.\" $FreeBSD$
2926b6c45aSRuslan Ermilov.\"
3074e03642STim J. Robbins.Dd February 15, 2000
31b0a1b4f8SJason Evans.Dt SEM_INIT 3
32b0a1b4f8SJason Evans.Os
33b0a1b4f8SJason Evans.Sh NAME
34b0a1b4f8SJason Evans.Nm sem_init
35b0a1b4f8SJason Evans.Nd initialize an unnamed semaphore
36d8a78688SAlexey Zelkin.Sh LIBRARY
37fccedf06SRuslan Ermilov.Lb libc
38b0a1b4f8SJason Evans.Sh SYNOPSIS
3932eef9aeSRuslan Ermilov.In semaphore.h
40b0a1b4f8SJason Evans.Ft int
41b0a1b4f8SJason Evans.Fn sem_init "sem_t *sem" "int pshared" "unsigned int value"
42b0a1b4f8SJason Evans.Sh DESCRIPTION
43b0a1b4f8SJason EvansThe
44b0a1b4f8SJason Evans.Fn sem_init
45b0a1b4f8SJason Evansfunction initializes the unnamed semaphore pointed to by
46b0a1b4f8SJason Evans.Fa sem
47b0a1b4f8SJason Evansto have the value
48b0a1b4f8SJason Evans.Fa value .
49b0a1b4f8SJason EvansA non-zero value for
50b0a1b4f8SJason Evans.Fa pshared
5174e03642STim J. Robbinsspecifies a shared semaphore that can be used by multiple processes, which this
5274e03642STim J. Robbinsimplementation is not capable of.
53b0a1b4f8SJason Evans.Pp
54b0a1b4f8SJason EvansFollowing a successful call to
55b0a1b4f8SJason Evans.Fn sem_init ,
56b0a1b4f8SJason Evans.Fa sem
57b0a1b4f8SJason Evanscan be used as an argument in subsequent calls to
589d09157aSPhilippe Charnier.Xr sem_wait 3 ,
599d09157aSPhilippe Charnier.Xr sem_trywait 3 ,
609d09157aSPhilippe Charnier.Xr sem_post 3 ,
61b0a1b4f8SJason Evansand
629d09157aSPhilippe Charnier.Xr sem_destroy 3 .
639d09157aSPhilippe CharnierThe
64b0a1b4f8SJason Evans.Fa sem
659d09157aSPhilippe Charnierargument is no longer valid after a successful call to
669d09157aSPhilippe Charnier.Xr sem_destroy 3 .
67b0a1b4f8SJason Evans.Sh RETURN VALUES
68b1250632SYaroslav Tykhiy.Rv -std sem_init
69b0a1b4f8SJason Evans.Sh ERRORS
709d09157aSPhilippe CharnierThe
71b0a1b4f8SJason Evans.Fn sem_init
729d09157aSPhilippe Charnierfunction will fail if:
73b0a1b4f8SJason Evans.Bl -tag -width Er
74b0a1b4f8SJason Evans.It Bq Er EINVAL
7526b6c45aSRuslan ErmilovThe
76b0a1b4f8SJason Evans.Fa value
7726b6c45aSRuslan Ermilovargument exceeds
7826b6c45aSRuslan Ermilov.Dv SEM_VALUE_MAX .
79b0a1b4f8SJason Evans.It Bq Er ENOSPC
80b0a1b4f8SJason EvansMemory allocation error.
8174e03642STim J. Robbins.It Bq Er EPERM
8274e03642STim J. RobbinsUnable to initialize a shared semaphore.
83b0a1b4f8SJason Evans.El
84b0a1b4f8SJason Evans.Sh SEE ALSO
8582db3da3SJason Evans.Xr sem_destroy 3 ,
86b0a1b4f8SJason Evans.Xr sem_post 3 ,
8782db3da3SJason Evans.Xr sem_trywait 3 ,
8851f2ddd7STim J. Robbins.Xr sem_wait 3 ,
8951f2ddd7STim J. Robbins.Xr sem 4
90b0a1b4f8SJason Evans.Sh STANDARDS
919d09157aSPhilippe CharnierThe
92b0a1b4f8SJason Evans.Fn sem_init
939d09157aSPhilippe Charnierfunction conforms to
94096841ecSRuslan Ermilov.St -p1003.1-96 .
9574e03642STim J. Robbins.Pp
9674e03642STim J. RobbinsThis implementation does not support shared semaphores, and reports this fact
9774e03642STim J. Robbinsby setting
9874e03642STim J. Robbins.Va errno
9974e03642STim J. Robbinsto
10074e03642STim J. Robbins.Er EPERM .
10126b6c45aSRuslan ErmilovThis is perhaps a stretch of the intention of
10226b6c45aSRuslan Ermilov.Tn POSIX ,
10326b6c45aSRuslan Ermilovbut is
10474e03642STim J. Robbinscompliant, with the caveat that
10574e03642STim J. Robbins.Fn sem_init
10674e03642STim J. Robbinsalways reports a permissions error when an attempt to create a shared semaphore
10774e03642STim J. Robbinsis made.
108