wait on a semaphore, but don't block
#include <semaphore.h> int sem_trywait( sem_t *sem );
The sem_trywait() function decrements the semaphore if the semaphore's value is greater than zero, otherwise the function simply returns.
If the semaphore was successfully decremented, sem_trywait() returns zero. Otherwise, the state of the semaphore is unchanged and -1 is returned, with errno set to indicate the error.
/usr/demo/src/semaphores
POSIX 1003.1b-1993
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
errno, sem_destroy(), sem_init(), sem_post(), sem_wait()