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.\" 288916af88SJohn Baldwin.Dd April 16, 2013 29b0a1b4f8SJason Evans.Dt SEM_WAIT 3 30b0a1b4f8SJason Evans.Os 31b0a1b4f8SJason Evans.Sh NAME 32b0a1b4f8SJason Evans.Nm sem_wait , 33b0a1b4f8SJason Evans.Nm sem_trywait 34b0a1b4f8SJason Evans.Nd decrement (lock) a semaphore 35d8a78688SAlexey Zelkin.Sh LIBRARY 36fccedf06SRuslan Ermilov.Lb libc 37b0a1b4f8SJason Evans.Sh SYNOPSIS 3832eef9aeSRuslan Ermilov.In semaphore.h 39b0a1b4f8SJason Evans.Ft int 40b0a1b4f8SJason Evans.Fn sem_wait "sem_t *sem" 41b0a1b4f8SJason Evans.Ft int 42b0a1b4f8SJason Evans.Fn sem_trywait "sem_t *sem" 43b0a1b4f8SJason Evans.Sh DESCRIPTION 44b0a1b4f8SJason EvansThe 45b0a1b4f8SJason Evans.Fn sem_wait 46b0a1b4f8SJason Evansfunction decrements (locks) the semaphore pointed to by 47b0a1b4f8SJason Evans.Fa sem , 48b0a1b4f8SJason Evansbut blocks if the value of 49b0a1b4f8SJason Evans.Fa sem 50b0a1b4f8SJason Evansis zero, until the value is non-zero and the value can be decremented. 51b0a1b4f8SJason Evans.Pp 52b0a1b4f8SJason EvansThe 53b0a1b4f8SJason Evans.Fn sem_trywait 54b0a1b4f8SJason Evansfunction decrements (locks) the semaphore pointed to by 55b0a1b4f8SJason Evans.Fa sem 5626b6c45aSRuslan Ermilovonly if the value is non-zero. 5726b6c45aSRuslan ErmilovOtherwise, the semaphore is not decremented and 58b0a1b4f8SJason Evansan error is returned. 59b0a1b4f8SJason Evans.Sh RETURN VALUES 60d6002fefSRuslan Ermilov.Rv -std 61b0a1b4f8SJason Evans.Sh ERRORS 629d09157aSPhilippe CharnierThe 63b0a1b4f8SJason Evans.Fn sem_wait 64b0a1b4f8SJason Evansand 65b0a1b4f8SJason Evans.Fn sem_trywait 669d09157aSPhilippe Charnierfunctions will fail if: 67b0a1b4f8SJason Evans.Bl -tag -width Er 68b0a1b4f8SJason Evans.It Bq Er EINVAL 6926b6c45aSRuslan ErmilovThe 70b0a1b4f8SJason Evans.Fa sem 7126b6c45aSRuslan Ermilovargument 72b0a1b4f8SJason Evanspoints to an invalid semaphore. 73b0a1b4f8SJason Evans.El 74b0a1b4f8SJason Evans.Pp 75b0a1b4f8SJason EvansAdditionally, 768916af88SJohn Baldwin.Fn sem_wait 778916af88SJohn Baldwinwill fail if: 788916af88SJohn Baldwin.Bl -tag -width Er 798916af88SJohn Baldwin.It Bq Er EINTR 808916af88SJohn BaldwinA signal interrupted this function. 818916af88SJohn Baldwin.El 821d8b56e9SSergey Kandaurov.Pp 838916af88SJohn BaldwinAdditionally, 84b0a1b4f8SJason Evans.Fn sem_trywait 85b0a1b4f8SJason Evanswill fail if: 86b0a1b4f8SJason Evans.Bl -tag -width Er 87b0a1b4f8SJason Evans.It Bq Er EAGAIN 88b0a1b4f8SJason EvansThe semaphore value was zero, and thus could not be decremented. 89b0a1b4f8SJason Evans.El 90b0a1b4f8SJason Evans.Sh SEE ALSO 917a6d1e6fSRobert Watson.Xr sem_getvalue 3 , 9251f2ddd7STim J. Robbins.Xr sem_post 3 , 93*15096da3SJohn Baldwin.Xr sem_timedwait 3 94b0a1b4f8SJason Evans.Sh STANDARDS 959d09157aSPhilippe CharnierThe 96b0a1b4f8SJason Evans.Fn sem_wait 97b0a1b4f8SJason Evansand 98b0a1b4f8SJason Evans.Fn sem_trywait 999d09157aSPhilippe Charnierfunctions conform to 100096841ecSRuslan Ermilov.St -p1003.1-96 . 101