[Previous] [Contents] [Next]

sem_wait()

Wait on a semaphore

Synopsis:

#include <semaphore.h>

int sem_wait( sem_t * sem );

Library:

libc

Description:

The sem_wait() function decrements the semaphore referred to by the sem argument. If the semaphore value is not greater than zero, then the calling process will block until it can decrement the counter or the call is interrupted by signal.

Some process should eventually call sem_post() to increment the semaphore.

Returns:

0
The semaphore was successfully decremented.
-1
The state of the semaphore is unchanged; errno is set to indicate the error.

Errors:

EDEADLK
A deadlock condition was detected.
EINVAL
Invalid semaphore descriptor sem.
EINTR
A signal interrupted this function.

Classification:

POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

sem_destroy(), sem_init(), sem_post(), sem_trywait()


[Previous] [Contents] [Next]