sem_post

Synopsis

#include <semaphore.h>

int sem_post(sem_t *sem);

Status

Implemented

Conformance

IEEE Std 1003.1-2024

Description

The sem_post() function shall unlock the semaphore referenced by sem. If any threads are blocked on the semaphore, one of them shall be allowed to return successfully; otherwise the semaphore value shall be incremented.

Both named and unnamed semaphores are accepted. On a named semaphore the waiter released is the highest priority one that has been waiting longest, which satisfies the scheduling requirement IEEE Std 1003.1-2024 states for SCHED_FIFO and SCHED_RR.

Return value

Upon successful completion, sem_post() shall return 0. Otherwise it shall return -1, the semaphore state shall be unchanged, and errno shall be set to indicate the error.

Errors

This function shall fail if:

  • EOVERFLOW - the maximum allowable value for a semaphore would be exceeded,

  • EINVAL - sem is a null pointer or does not refer to a valid semaphore,

  • EBADF - the named semaphore has been closed or removed.

POSIX deviations

No POSIX deviations discovered.