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 (REALTIME)
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

66       None.
67

APPLICATION USAGE

69       Applications using these functions may be subject  to  priority  inver‐
70       sion,    as    discussed    in   the   Base   Definitions   volume   of
71       IEEE Std 1003.1-2001, Section 3.285, Priority Inversion.
72
73       The sem_trywait() and sem_wait() functions are part of  the  Semaphores
74       option and need not be provided on all implementations.
75

RATIONALE

77       None.
78

FUTURE DIRECTIONS

80       None.
81

SEE ALSO

83       semctl(), semget(), semop(), sem_post(), sem_timedwait(), the Base Def‐
84       initions volume of IEEE Std 1003.1-2001, <semaphore.h>
85
87       Portions of this text are reprinted and reproduced in  electronic  form
88       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
89       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
90       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
91       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
92       event of any discrepancy between this version and the original IEEE and
93       The Open Group Standard, the original IEEE and The Open Group  Standard
94       is  the  referee document. The original Standard can be obtained online
95       at http://www.opengroup.org/unix/online.html .
96
97
98
99IEEE/The Open Group                  2003                      SEM_TRYWAIT(3P)
Impressum