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

NAME

6       sem_trywait, sem_wait - lock a semaphore (REALTIME)
7

SYNOPSIS

9       #include <semaphore.h>
10
11       int sem_trywait(sem_t *sem);
12       int sem_wait(sem_t *sem);
13
14

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

60       None.
61

APPLICATION USAGE

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

RATIONALE

71       None.
72

FUTURE DIRECTIONS

74       None.
75

SEE ALSO

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