[Previous]
[Contents]
[Next]

sem_wait()

wait on a semaphore

Synopsis:

#include <semaphore.h>
int sem_wait( sem_t *sem );

Description:

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.

Returns:

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.

Errors:

EDEADLK
A deadlock condition was detected.
EINVAL
The sem argument doesn't refer to a valid semaphore.
EINTR
A signal interrupted this function.
ENOSYS
The function sem_wait() isn't supported.

Examples:

/usr/demo/src/semaphores

Classification:

POSIX 1003.1b-1993

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

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


[Previous]
[Contents]
[Next]