1SEM_TRYWAIT(3P)            POSIX Programmer's Manual           SEM_TRYWAIT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       sem_trywait, sem_wait — lock a semaphore
13

SYNOPSIS

15       #include <semaphore.h>
16
17       int sem_trywait(sem_t *sem);
18       int sem_wait(sem_t *sem);
19

DESCRIPTION

21       The sem_trywait() function shall lock the semaphore referenced  by  sem
22       only  if  the  semaphore is currently not locked; that is, if the sema‐
23       phore value is currently positive. Otherwise, it  shall  not  lock  the
24       semaphore.
25
26       The  sem_wait()  function shall lock the semaphore referenced by sem by
27       performing a semaphore lock operation on that semaphore. If  the  sema‐
28       phore value is currently zero, then the calling thread shall not return
29       from the call to sem_wait() until it either locks the semaphore or  the
30       call is interrupted by a signal.
31
32       Upon  successful return, the state of the semaphore shall be locked and
33       shall remain locked until  the  sem_post()  function  is  executed  and
34       returns successfully.
35
36       The sem_wait() function is interruptible by the delivery of a signal.
37

RETURN VALUE

39       The  sem_trywait()  and  sem_wait()  functions shall return zero if the
40       calling process successfully performed the semaphore lock operation  on
41       the  semaphore  designated  by  sem.  If the call was unsuccessful, the
42       state of the semaphore shall  be  unchanged,  and  the  function  shall
43       return a value of -1 and set errno to indicate the error.
44

ERRORS

46       The sem_trywait() function shall fail if:
47
48       EAGAIN The  semaphore  was  already locked, so it cannot be immediately
49              locked by the sem_trywait() operation.
50
51       The sem_trywait() and sem_wait() functions may fail if:
52
53       EDEADLK
54              A deadlock condition was detected.
55
56       EINTR  A signal interrupted this function.
57
58       EINVAL The sem argument does not refer to a valid semaphore.
59
60       The following sections are informative.
61

EXAMPLES

63       None.
64

APPLICATION USAGE

66       Applications using these functions may be subject  to  priority  inver‐
67       sion, as discussed in the Base Definitions volume of POSIX.1‐2017, Sec‐
68       tion 3.291, Priority Inversion.
69

RATIONALE

71       None.
72

FUTURE DIRECTIONS

74       None.
75

SEE ALSO

77       semctl(), semget(), semop(), sem_post(), sem_timedwait()
78
79       The Base Definitions volume of POSIX.1‐2017,  Section  3.291,  Priority
80       Inversion, Section 4.12, Memory Synchronization, <semaphore.h>
81
83       Portions  of  this text are reprinted and reproduced in electronic form
84       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
85       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
86       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
87       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
88       event of any discrepancy between this version and the original IEEE and
89       The  Open Group Standard, the original IEEE and The Open Group Standard
90       is the referee document. The original Standard can be  obtained  online
91       at http://www.opengroup.org/unix/online.html .
92
93       Any  typographical  or  formatting  errors that appear in this page are
94       most likely to have been introduced during the conversion of the source
95       files  to  man page format. To report such errors, see https://www.ker
96       nel.org/doc/man-pages/reporting_bugs.html .
97
98
99
100IEEE/The Open Group                  2017                      SEM_TRYWAIT(3P)
Impressum