Unlocks a semaphore.
Standard C Library (libc.a)
#include <semaphore.h>
int sem_post (sem)
sem_t *sem;
The sem_post subroutine unlocks the semaphore referenced by the sem parameter by performing a semaphore unlock operation on that semaphore.
If the semaphore value resulting from this operation is positive, no threads were blocked waiting for the semaphore to become unlocked, and the semaphore value is incremented.
If the value of the semaphore resulting from this operation is zero, one of the threads blocked waiting for the semaphore is allowed to return successfully from its call to the sem_wait subroutine. If the Process Scheduling option is supported, the thread to be unblocked is chosen in a manner appropriate to the scheduling policies and parameters in effect for the blocked threads. In the case of the schedulers SCHED_FIFO and SCHED_RR, the highest priority waiting thread shall be is unblocked, and if there is more than one highest priority thread blocked waiting for the semaphore, then the highest priority thread that has been waiting the longest is unblocked. If the Process Scheduling option is not defined, the choice of a thread to unblock is unspecified.
If the Process Sporadic Server option is supported, and the scheduling policy is SCHED_SPORADIC, the semantics are the same as SCHED_FIFO in the preceding paragraph.
The sem_post subroutine is reentrant with respect to signals and may be invoked from a signal-catching function.
Item | Description |
---|---|
sem | Specifies the semaphore to be unlocked. |
If successful, the sem_post subroutine returns zero. Otherwise, it returns -1 and sets errno to indicate the error.
Item | Description |
---|---|
EACCES | Permission is denied to access the unnamed semaphore. |
EFAULT | Invalid user address. |
EIDRM | Semaphore was removed during the required operation. |
EINVAL | The sem parameter does not refer to a valid semaphore. |
ENOMEM | Insufficient memory for the required operation. |
ENOTSUP | This function is not supported with processes that have been checkpoint-restart'ed. |