Multithreaded Programming Guide

Exit Print View

Updated: July 2014
 
 

Incrementing a Semaphore

Use sem_post to atomically increment the semaphore pointed to by sem.

sem_post Syntax

int sem_post(sem_t *sem);
#include <semaphore.h>

sem_t sem;
int ret;

ret = sem_post(&sem); /* semaphore is posted */

When any threads are blocked on the semaphore, one of the threads is unblocked.

sem_post Return Values

sem_post() returns zero after completing successfully. Any other return value indicates that an error occurred. When the following condition occurs, the function fails and returns the corresponding value.

EINVAL

Description: sem points to an illegal address.