[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    sem_post(3R) manual page Table of Contents

Name

sem_post - increment the count of a semaphore

Synopsis

cc [ flag ... ] file ... -lposix4 [ library ... ]

#include <semaphore.h>

int sem_post(sem_t *sem);

typedef struct {
...

} sem_t /*opaque POSIX.4 semaphore*/

MT-Level

Async-Signal-Safe

Description

If, prior to the call to sem_post(), the value of sem was 0, and other processes (or LWPs or threads) were blocked waiting for the semaphore, then one of them will be allowed to return successfully from its call to sem_wait(3R) . The process to be unblocked will be chosen in a manner appropriate to the scheduling policies and parameters in effect for the blocked processes. In the case of the policies SCHED_FIFO and SCHED_RR, the highest priority waiting process is unblocked, and if there is more than one highest-priority process blocked waiting for the semaphore, then the highest priority process which has been waiting the longest is unblocked.

If, prior to the call to sem_post(), no other processes ( or LWPs or thread) were blocked for the semaphore, then its value is incremented by one.

sem_post() is reentrant with respect to signals (ASYNC-SAFE), and may be invoked from a signal-catching function. The semaphore functionality described on this man page is for the POSIX threads implementation. For the documentation of the Solaris threads interface, see semaphore(3T) ).

Return Values

If successful, sem_post() returns 0, otherwise it returns -1, and sets errno to indicate the error condition.

Errors

EINVAL
sem does not refer to a valid semaphore.
ENOSYS
sem_post() is not supported by this implementation.

Examples

(see sem_wait(3R) )

See Also

sched_setscheduler(3R) , sem_wait(3R) , semaphore(3T)

Notes

sem_wait(3R) and sem_trywait(3R) decrement the semaphore upon their successful return.

Bugs

In Solaris 2.5, these functions always return -1 and set errno to ENOSYS, because this release does not support the Semaphores option. It is our intention to provide support for these interfaces in future releases.


Table of Contents