Multithreaded Programming Guide

Increment a Semaphore

Use sema_post(3C) to atomically increment the semaphore pointed to by sp. When any threads are blocked on the semaphore, one thread is unblocked.

sema_post Syntax

#include <thread.h>

int sema_post(sema_t *sp);

sema_post Return Values

sema_post() returns 0 if successful. When any of the following conditions is detected, sema_post() fails and returns the corresponding value.


EINVAL

Description:

sp refers to an invalid semaphore.


EFAULT

Description:

sp points to an illegal address.


EOVERFLOW

Description:

The semaphore value pointed to by sp exceeds SEM_VALUE_MAX.