sem_post()

QNX SDP8.0C Library ReferenceAPIDeveloper

Increment a named or unnamed semaphore

Synopsis:

#include <semaphore.h>

int sem_post( sem_t * sem );

Arguments:

sem
A pointer to the sem_t object for the semaphore whose value you want to increment.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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

The thread to be unblocked is determined in accordance with the scheduling policies in effect for the blocked threads. The highest priority waiting thread 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.

The sem_post() function is reentrant with respect to signals, and can be called from a signal handler.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EINTR
The call was interrupted by a signal.
EINVAL
The sem argument doesn't point to a valid semaphore descriptor.
EOVERFLOW
The semaphore would exceed its maximum value (SEM_VALUE_MAX).

Classification:

POSIX 1003.1

Safety:
Cancellation pointNo
Signal handlerYes
ThreadYes
Page updated: