1*bda456ccSpirofti.\" $OpenBSD: sem_wait.3,v 1.10 2018/04/24 16:28:42 pirofti Exp $ 2ea5298d1Sfgsch.\" 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_wait.3,v 1.8 2001/10/01 16:09:09 ru Exp $ 31*bda456ccSpirofti.Dd $Mdocdate: April 24 2018 $ 322787694aSfgsch.Dt SEM_WAIT 3 332787694aSfgsch.Os 342787694aSfgsch.Sh NAME 352787694aSfgsch.Nm sem_wait , 3624d36301Sjmc.Nm sem_timedwait , 372787694aSfgsch.Nm sem_trywait 382787694aSfgsch.Nd decrement (lock) a semaphore 392787694aSfgsch.Sh SYNOPSIS 4086f9d4cdStedu.In semaphore.h 412787694aSfgsch.Ft int 422787694aSfgsch.Fn sem_wait "sem_t *sem" 432787694aSfgsch.Ft int 4449f43da5Sguenther.Fn sem_timedwait "sem_t *sem" "const struct timespec *abstime" 4549f43da5Sguenther.Ft int 462787694aSfgsch.Fn sem_trywait "sem_t *sem" 472787694aSfgsch.Sh DESCRIPTION 482787694aSfgschThe 492787694aSfgsch.Fn sem_wait 502787694aSfgschfunction decrements (locks) the semaphore pointed to by 512787694aSfgsch.Fa sem , 522787694aSfgschbut blocks if the value of 532787694aSfgsch.Fa sem 542787694aSfgschis zero, until the value is non-zero and the value can be decremented. 552787694aSfgsch.Pp 562787694aSfgschThe 5749f43da5Sguenther.Fn sem_timedwait 5849f43da5Sguentherfunction decrements (locks) the semaphore pointed to by 5949f43da5Sguenther.Fa sem , 6049f43da5Sguentherbut blocks if the value of 6149f43da5Sguenther.Fa sem 6249f43da5Sguentheris zero, until either the value is non-zero and can be decremented 6349f43da5Sguentheror the system time specified by 6449f43da5Sguenther.Fa abstime 6549f43da5Sguentheris reached. 6649f43da5Sguenther.Pp 6749f43da5SguentherThe 682787694aSfgsch.Fn sem_trywait 692787694aSfgschfunction decrements (locks) the semaphore pointed to by 702787694aSfgsch.Fa sem 71ee997aeaSmpechonly if the value is non-zero. 72ee997aeaSmpechOtherwise, the semaphore is not decremented and 732787694aSfgschan error is returned. 742787694aSfgsch.Sh RETURN VALUES 7549f43da5Sguenther.Rv -std sem_wait sem_timedwait sem_trywait 762787694aSfgsch.Sh ERRORS 7749f43da5Sguenther.Fn sem_wait , 7849f43da5Sguenther.Fn sem_timedwait , 792787694aSfgschand 802787694aSfgsch.Fn sem_trywait 812787694aSfgschwill fail if: 822787694aSfgsch.Bl -tag -width Er 832787694aSfgsch.It Bq Er EINVAL 842787694aSfgsch.Fa sem 852787694aSfgschpoints to an invalid semaphore. 862787694aSfgsch.El 872787694aSfgsch.Pp 882787694aSfgschAdditionally, 89*bda456ccSpirofti.Fn sem_wait 90*bda456ccSpiroftiand 9149f43da5Sguenther.Fn sem_timedwait 9249f43da5Sguentherwill fail if: 9349f43da5Sguenther.Bl -tag -width Er 94*bda456ccSpirofti.It Bq Er EINTR 95*bda456ccSpiroftiThe call was interrupted by a signal. 96*bda456ccSpirofti.El 97*bda456ccSpirofti.Pp 98*bda456ccSpiroftiAdditionally, 99*bda456ccSpirofti.Fn sem_timedwait 100*bda456ccSpiroftiwill fail if: 101*bda456ccSpirofti.Bl -tag -width Er 102*bda456ccSpirofti.It Bq Er EINVAL 103*bda456ccSpirofti.Fa abstime 104*bda456ccSpiroftiwas 105*bda456ccSpirofti.Dv NULL 106*bda456ccSpiroftior specified a nanosecond value less than zero or greater than 1000 million. 10749f43da5Sguenther.It Bq Er ETIMEDOUT 10849f43da5SguentherThe semaphore value was zero and could not be decremented before 10949f43da5Sguenther.Fa abstime 11049f43da5Sguentherwas reached. 11149f43da5Sguenther.El 11249f43da5Sguenther.Pp 11349f43da5SguentherAdditionally, 1142787694aSfgsch.Fn sem_trywait 1152787694aSfgschwill fail if: 1162787694aSfgsch.Bl -tag -width Er 1172787694aSfgsch.It Bq Er EAGAIN 1182787694aSfgschThe semaphore value was zero, and thus could not be decremented. 1192787694aSfgsch.El 1202787694aSfgsch.Sh SEE ALSO 1219c42db49Sjmc.Xr sem_destroy 3 , 1229c42db49Sjmc.Xr sem_getvalue 3 , 1239c42db49Sjmc.Xr sem_init 3 , 1249c42db49Sjmc.Xr sem_open 3 , 1252787694aSfgsch.Xr sem_post 3 1262787694aSfgsch.Sh STANDARDS 12749f43da5Sguenther.Fn sem_wait , 12849f43da5Sguenther.Fn sem_timedwait , 1292787694aSfgschand 1302787694aSfgsch.Fn sem_trywait 1312787694aSfgschconform to 13249f43da5Sguenther.St -p1003.1-2008 . 133