sem_post()

unlock a semaphore 

Realtime Function


SYNOPSIS

#include <semaphore.h>

int sem_post(sem_t *sem);


DESCRIPTION

The sem_post() function unlocks the specified semaphore by performing a semaphore unlock operation on that semaphore.

When this operation results in a positive semaphore value, no threads were blocked waiting for the semaphore to be unlocked; the semaphore value is simply incremented.

When this operation results in a semaphore value of zero, one of the threads waiting for the semaphore is allowed to return successfully from its invocation of the sem_wait() function.

The sem_post() interface is reentrant with respect to signals and may be invoked from a signal-catching function.


PARAMETERS

sem 

Specifies a semaphore to be unlocked.


RETURN VALUES

When sem_post() is successful, it returns zero. Otherwise, it returns -1 and set errno to one of the following values:

EINVAL 

The sem argument is not a valid semaphore.


EXAMPLES

None.


CONFORMANCE

UNIX 03. Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

On Windows, the waiting thread that is allowed to return is chosen by the Win32 WaitForMultipleObjects() function.

On UNIX platforms, this thread is chosen differently, If the _POSIX_PRIORITY_SCHEDULING symbol is defined, sem_post() uses the scheduling policies and parameters in effect for the block threads to choose which thread is to be unlocked. For the SCHED_FIFO and SCHED_RR schedulers, the waiting thread with the highest priority waiting thread is unblocked, and if two or more blocked threads share the highest priority, the one that has been waiting the longest is unblocked. If _POSIX_PRIORITY_SCHEDULING is not defined, it is unspecified as to which thread is unblocked.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
sem_trywait(), sem_wait(), semctl(), semget(), semop()

Miscellaneous:
semaphores


PTC MKS Toolkit 10.3 Documentation Build 39.