1*512b5dedSjmc.\" $OpenBSD: sem_init.3,v 1.8 2023/02/11 21:13:56 jmc Exp $ 2a72c0c24Sfgsch.\" 32787694aSfgsch.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>. 42787694aSfgsch.\" All rights reserved. 52787694aSfgsch.\" 62787694aSfgsch.\" Redistribution and use in source and binary forms, with or without 72787694aSfgsch.\" modification, are permitted provided that the following conditions 82787694aSfgsch.\" are met: 92787694aSfgsch.\" 1. Redistributions of source code must retain the above copyright 102787694aSfgsch.\" notice(s), this list of conditions and the following disclaimer as 112787694aSfgsch.\" the first lines of this file unmodified other than the possible 122787694aSfgsch.\" addition of one or more copyright notices. 132787694aSfgsch.\" 2. Redistributions in binary form must reproduce the above copyright 142787694aSfgsch.\" notice(s), this list of conditions and the following disclaimer in 152787694aSfgsch.\" the documentation and/or other materials provided with the 162787694aSfgsch.\" distribution. 172787694aSfgsch.\" 182787694aSfgsch.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 192787694aSfgsch.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202787694aSfgsch.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 212787694aSfgsch.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 222787694aSfgsch.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 232787694aSfgsch.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 242787694aSfgsch.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 252787694aSfgsch.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 262787694aSfgsch.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 272787694aSfgsch.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 282787694aSfgsch.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292787694aSfgsch.\" 302787694aSfgsch.\" $FreeBSD: src/lib/libc_r/man/sem_init.3,v 1.11 2001/10/01 16:09:09 ru Exp $ 31*512b5dedSjmc.Dd $Mdocdate: February 11 2023 $ 322787694aSfgsch.Dt SEM_INIT 3 332787694aSfgsch.Os 342787694aSfgsch.Sh NAME 352787694aSfgsch.Nm sem_init 362787694aSfgsch.Nd initialize an unnamed semaphore 372787694aSfgsch.Sh SYNOPSIS 3886f9d4cdStedu.In semaphore.h 392787694aSfgsch.Ft int 402787694aSfgsch.Fn sem_init "sem_t *sem" "int pshared" "unsigned int value" 412787694aSfgsch.Sh DESCRIPTION 422787694aSfgschThe 432787694aSfgsch.Fn sem_init 442787694aSfgschfunction initializes the unnamed semaphore pointed to by 452787694aSfgsch.Fa sem 462787694aSfgschto have the value 472787694aSfgsch.Fa value . 482787694aSfgschA non-zero value for 492787694aSfgsch.Fa pshared 503bcf74b6Sknspecifies a shared semaphore that can be used by multiple processes, which this 513bcf74b6Sknimplementation is not capable of. 522787694aSfgsch.Pp 532787694aSfgschFollowing a successful call to 542787694aSfgsch.Fn sem_init , 552787694aSfgsch.Fa sem 562787694aSfgschcan be used as an argument in subsequent calls to 57*512b5dedSjmc.Xr sem_wait 3 , 58*512b5dedSjmc.Xr sem_trywait 3 , 59*512b5dedSjmc.Xr sem_post 3 , 602787694aSfgschand 61*512b5dedSjmc.Xr sem_destroy 3 . 622787694aSfgsch.Fa sem 632787694aSfgschis no longer valid after a successful call to 64*512b5dedSjmc.Xr sem_destroy 3 . 652787694aSfgsch.Sh RETURN VALUES 662787694aSfgsch.Rv -std sem_init 672787694aSfgsch.Sh ERRORS 68772c37b9SteduIt is an error to call 69*512b5dedSjmc.Xr sem_destroy 3 70772c37b9Steduon a named semaphore created by 71*512b5dedSjmc.Xr sem_open 3 . 72772c37b9Stedu.Pp 732787694aSfgsch.Fn sem_init 742787694aSfgschwill fail if: 752787694aSfgsch.Bl -tag -width Er 762787694aSfgsch.It Bq Er EINVAL 772787694aSfgsch.Fa value 782787694aSfgschexceeds SEM_VALUE_MAX. 792787694aSfgsch.It Bq Er ENOSPC 802787694aSfgschMemory allocation error. 813bcf74b6Skn.It Bq Er EPERM 823bcf74b6SknUnable to initialize a shared semaphore. 832787694aSfgsch.El 842787694aSfgsch.Sh SEE ALSO 852787694aSfgsch.Xr sem_destroy 3 , 869c42db49Sjmc.Xr sem_getvalue 3 , 879c42db49Sjmc.Xr sem_open 3 , 882787694aSfgsch.Xr sem_post 3 , 892787694aSfgsch.Xr sem_wait 3 902787694aSfgsch.Sh STANDARDS 912787694aSfgsch.Fn sem_init 922787694aSfgschconforms to 932787694aSfgsch.St -p1003.1-96 . 943bcf74b6Skn.Pp 953bcf74b6SknThis implementation does not support shared semaphores, and reports this fact 963bcf74b6Sknby setting 973bcf74b6Skn.Va errno 983bcf74b6Sknto 993bcf74b6Skn.Er EPERM . 1003bcf74b6SknThis is perhaps a stretch of the intention of POSIX, but is 1013bcf74b6Skncompliant, with the caveat that 1023bcf74b6Skn.Fn sem_init 1033bcf74b6Sknalways reports a permissions error when an attempt to create a shared semaphore 1043bcf74b6Sknis made. 105