wait on a semaphore
#include <semaphore.h> int sem_wait( sem_t *sem );
The sem_wait() function decrements the semaphore referred to by the sem argument. If the semaphore value isn't greater than zero, the calling process will block until it can decrement the counter or the call is interrupted by signal.
The calling process should eventually call sem_post() to increment the semaphore.
If the semaphore was successfully decremented, sem_wait() 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_trywait()