1*2252cc8cSchristos.\" $NetBSD: sem_init.3,v 1.5 2019/02/21 21:54:09 christos Exp $ 237946878Sthorpej.\" 337946878Sthorpej.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>. 437946878Sthorpej.\" All rights reserved. 537946878Sthorpej.\" 637946878Sthorpej.\" Redistribution and use in source and binary forms, with or without 737946878Sthorpej.\" modification, are permitted provided that the following conditions 837946878Sthorpej.\" are met: 937946878Sthorpej.\" 1. Redistributions of source code must retain the above copyright 1037946878Sthorpej.\" notice(s), this list of conditions and the following disclaimer as 1137946878Sthorpej.\" the first lines of this file unmodified other than the possible 1237946878Sthorpej.\" addition of one or more copyright notices. 1337946878Sthorpej.\" 2. Redistributions in binary form must reproduce the above copyright 1437946878Sthorpej.\" notice(s), this list of conditions and the following disclaimer in 1537946878Sthorpej.\" the documentation and/or other materials provided with the 1637946878Sthorpej.\" distribution. 1737946878Sthorpej.\" 1837946878Sthorpej.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 1937946878Sthorpej.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2037946878Sthorpej.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2137946878Sthorpej.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 2237946878Sthorpej.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2337946878Sthorpej.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2437946878Sthorpej.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2537946878Sthorpej.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2637946878Sthorpej.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 2737946878Sthorpej.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 2837946878Sthorpej.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2937946878Sthorpej.\" 30*2252cc8cSchristos.Dd February 21, 2019 3137946878Sthorpej.Dt SEM_INIT 3 3237946878Sthorpej.Os 3337946878Sthorpej.Sh NAME 3437946878Sthorpej.Nm sem_init 3537946878Sthorpej.Nd initialize an unnamed semaphore 3637946878Sthorpej.Sh LIBRARY 3737946878Sthorpej.Lb librt 3837946878Sthorpej.Sh SYNOPSIS 3937946878Sthorpej.In semaphore.h 4037946878Sthorpej.Ft int 4137946878Sthorpej.Fn sem_init "sem_t *sem" "int pshared" "unsigned int value" 4237946878Sthorpej.Sh DESCRIPTION 4337946878SthorpejThe 4437946878Sthorpej.Fn sem_init 4537946878Sthorpejfunction initializes the unnamed semaphore pointed to by 4637946878Sthorpej.Fa sem 4737946878Sthorpejto have the value 4837946878Sthorpej.Fa value . 4937946878SthorpejA non-zero value for 5037946878Sthorpej.Fa pshared 5139c83c81Sjoergspecifies a shared semaphore that can be used by multiple processes. 5237946878Sthorpej.Pp 5337946878SthorpejFollowing a successful call to 5437946878Sthorpej.Fn sem_init , 5537946878Sthorpej.Fa sem 5637946878Sthorpejcan be used as an argument in subsequent calls to 574acff4c0Sjoerg.Fn sem_wait , 584acff4c0Sjoerg.Fn sem_timedwait , 594acff4c0Sjoerg.Fn sem_trywait , 604acff4c0Sjoerg.Fn sem_post , 6137946878Sthorpejand 624acff4c0Sjoerg.Fn sem_destroy . 6337946878Sthorpej.Fa sem 6437946878Sthorpejis no longer valid after a successful call to 6537946878Sthorpej.Fa sem_destroy . 6637946878Sthorpej.Sh RETURN VALUES 6737946878Sthorpej.Rv -std sem_init 6837946878Sthorpej.Sh ERRORS 6937946878Sthorpej.Fn sem_init 7037946878Sthorpejwill fail if: 7137946878Sthorpej.Bl -tag -width Er 7237946878Sthorpej.It Bq Er EINVAL 7337946878Sthorpej.Fa value 7437946878Sthorpejexceeds SEM_VALUE_MAX. 7537946878Sthorpej.It Bq Er ENOSPC 76*2252cc8cSchristosThere was memory allocation error, or the limit on available semaphores 77*2252cc8cSchristos.Dv ( SEM_NSEMS_MAX ) 78*2252cc8cSchristoshas been exceeded. 7937946878Sthorpej.It Bq Er EPERM 8037946878SthorpejUnable to initialize a shared semaphore. 8137946878Sthorpej.El 8237946878Sthorpej.Sh SEE ALSO 8337946878Sthorpej.Xr sem_destroy 3 , 8437946878Sthorpej.Xr sem_post 3 , 854acff4c0Sjoerg.Xr sem_timedwait 3 , 8637946878Sthorpej.Xr sem_trywait 3 , 8737946878Sthorpej.Xr sem_wait 3 8837946878Sthorpej.Sh STANDARDS 8937946878Sthorpej.Fn sem_init 9037946878Sthorpejconforms to 9137946878Sthorpej.St -p1003.1-96 . 92