[Previous]
[Contents]
[Next]

sem_post()

increment a semaphore

Synopsis:

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

Description:

The sem_post() function increments the semaphore referenced by the sem argument. If any processes are currently blocked waiting for the semaphore, one of these processes will return successfully from its call to sem_wait.

The process to be unblocked is determined in accordance with the scheduling policies in effect for the blocked processes. The highest priority waiting process is unblocked, and if there's more than one highest priority process blocked waiting for the semaphore, the highest priority process that has been waiting the longest is unblocked.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EINVAL
The sem argument doesn't refer to a valid semaphore.
ENOSYS
The sem_post() function 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_trywait(), sem_wait()


[Previous]
[Contents]
[Next]