Wait on a semaphore, but don't block
#include <semaphore.h>
int sem_trywait( sem_t * sem );
libc
The sem_trywait() function decrements the semaphore if the
semaphore's value is greater than zero; otherwise, the function simply returns.
- 0
- The semaphore was successfully decremented.
- -1
- The state of the semaphore is unchanged; errno is set to indicate the error.
- EAGAIN
- The semaphore was already locked, so it couldn't be
immediately locked by the sem_trywait() function.
- EDEADLK
- A deadlock condition was detected.
- EINVAL
- Invalid semaphore descriptor sem.
- EINTR
- A signal interrupted this function.
POSIX 1003.1
| Safety: | |
| Cancellation point |
No |
| Interrupt handler |
No |
| Signal handler |
Yes |
| Thread |
Yes |
sem_destroy(),
sem_init(),
sem_post(),
sem_wait()