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.\" 287bf27b2dSDavid Xu.Dd January 9, 2010 29b0a1b4f8SJason Evans.Dt SEM_INIT 3 30b0a1b4f8SJason Evans.Os 31b0a1b4f8SJason Evans.Sh NAME 32b0a1b4f8SJason Evans.Nm sem_init 33b0a1b4f8SJason Evans.Nd initialize an unnamed semaphore 34d8a78688SAlexey Zelkin.Sh LIBRARY 35fccedf06SRuslan Ermilov.Lb libc 36b0a1b4f8SJason Evans.Sh SYNOPSIS 3732eef9aeSRuslan Ermilov.In semaphore.h 38b0a1b4f8SJason Evans.Ft int 39b0a1b4f8SJason Evans.Fn sem_init "sem_t *sem" "int pshared" "unsigned int value" 40b0a1b4f8SJason Evans.Sh DESCRIPTION 41b0a1b4f8SJason EvansThe 42b0a1b4f8SJason Evans.Fn sem_init 43b0a1b4f8SJason Evansfunction initializes the unnamed semaphore pointed to by 44b0a1b4f8SJason Evans.Fa sem 45b0a1b4f8SJason Evansto have the value 46b0a1b4f8SJason Evans.Fa value . 47a455039eSDavid Xu.Pp 48b0a1b4f8SJason EvansA non-zero value for 49b0a1b4f8SJason Evans.Fa pshared 50a455039eSDavid Xuspecifies a shared semaphore that can be used by multiple processes, 51a455039eSDavid Xuthe semaphore should be located in shared memory region (see 52a455039eSDavid Xu.Xr mmap 2 , 53a455039eSDavid Xu.Xr shm_open 2 , 54a455039eSDavid Xuand 55a455039eSDavid Xu.Xr shmget 2 ) , 56a455039eSDavid Xuany process having read and write access to address 57a455039eSDavid Xu.Fa sem 58a455039eSDavid Xucan perform semaphore operations on 59a455039eSDavid Xu.Fa sem . 60b0a1b4f8SJason Evans.Pp 61b0a1b4f8SJason EvansFollowing a successful call to 62b0a1b4f8SJason Evans.Fn sem_init , 63b0a1b4f8SJason Evans.Fa sem 64b0a1b4f8SJason Evanscan be used as an argument in subsequent calls to 659d09157aSPhilippe Charnier.Xr sem_wait 3 , 669d09157aSPhilippe Charnier.Xr sem_trywait 3 , 679d09157aSPhilippe Charnier.Xr sem_post 3 , 68b0a1b4f8SJason Evansand 699d09157aSPhilippe Charnier.Xr sem_destroy 3 . 709d09157aSPhilippe CharnierThe 71b0a1b4f8SJason Evans.Fa sem 729d09157aSPhilippe Charnierargument is no longer valid after a successful call to 739d09157aSPhilippe Charnier.Xr sem_destroy 3 . 74b0a1b4f8SJason Evans.Sh RETURN VALUES 75b1250632SYaroslav Tykhiy.Rv -std sem_init 76b0a1b4f8SJason Evans.Sh ERRORS 779d09157aSPhilippe CharnierThe 78b0a1b4f8SJason Evans.Fn sem_init 799d09157aSPhilippe Charnierfunction will fail if: 80b0a1b4f8SJason Evans.Bl -tag -width Er 81b0a1b4f8SJason Evans.It Bq Er EINVAL 8226b6c45aSRuslan ErmilovThe 83b0a1b4f8SJason Evans.Fa value 8426b6c45aSRuslan Ermilovargument exceeds 8526b6c45aSRuslan Ermilov.Dv SEM_VALUE_MAX . 86b0a1b4f8SJason Evans.It Bq Er ENOSPC 87b0a1b4f8SJason EvansMemory allocation error. 88b0a1b4f8SJason Evans.El 89b0a1b4f8SJason Evans.Sh SEE ALSO 9082db3da3SJason Evans.Xr sem_destroy 3 , 917a6d1e6fSRobert Watson.Xr sem_getvalue 3 , 92b0a1b4f8SJason Evans.Xr sem_post 3 , 9382db3da3SJason Evans.Xr sem_trywait 3 , 94*15096da3SJohn Baldwin.Xr sem_wait 3 95b0a1b4f8SJason Evans.Sh STANDARDS 969d09157aSPhilippe CharnierThe 97b0a1b4f8SJason Evans.Fn sem_init 989d09157aSPhilippe Charnierfunction conforms to 99096841ecSRuslan Ermilov.St -p1003.1-96 . 100