---
name: "sem_post"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/sem_post/3"
---

# sem\_post(3)

increment (unlock) a semaphore

## NAME

**sem\_post** – increment (unlock) a semaphore

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<semaphore.h\>**

*int*\

**sem\_post**(*sem\_t \*sem*);

## DESCRIPTION

The **sem\_post**() function increments (unlocks) the semaphore pointed to by *sem*. If there are threads blocked on the semaphore when **sem\_post**() is called, then the highest priority thread that has been blocked the longest on the semaphore will be allowed to return from **sem\_wait**().

The **sem\_post**() function is signal-reentrant and may be called within signal handlers.

## RETURN VALUES

The **sem\_post()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## ERRORS

The **sem\_post**() function will fail if:

- \[EINVAL\]

  The *sem* argument points to an invalid semaphore.

- \[EOVERFLOW\]

  The semaphore value would exceed SEM\_VALUE\_MAX.

## SEE ALSO

[sem\_getvalue(3)](/sem_getvalue/3.md), [sem\_trywait(3)](/sem_trywait/3.md), [sem\_wait(3)](/sem_wait/3.md)

## STANDARDS

The **sem\_post**() function conforms to ISO/IEC 9945-1:1996 (“POSIX.1”).
