---
name: "sem_post"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/sem_post/3"
---

# sem\_post(3)

unlock a semaphore

## NAME

sem\_post - unlock a semaphore

## LIBRARY

POSIX threads library (*libpthread*, *-lpthread*)

## SYNOPSIS

```
#include <semaphore.h>
```

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

## DESCRIPTION

**sem\_post**() increments (unlocks) the semaphore pointed to by *sem*. If the semaphore's value consequently becomes greater than zero, then another process or thread blocked in a [**sem\_wait**(3)](/sem_wait/3.md) call will be woken up and proceed to lock the semaphore.

## RETURN VALUE

**sem\_post**() returns 0 on success; on error, the value of the semaphore is left unchanged, -1 is returned, and *errno* is set to indicate the error.

## ERRORS

- **EINVAL**

  *sem* is not a valid semaphore.

- **EOVERFLOW**

  The value would exceed **SEM\_VALUE\_MAX**.

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **sem\_post**() | Thread safety | MT-Safe |

## STANDARDS

POSIX.1-2008.

## HISTORY

POSIX.1-2001.

## NOTES

**sem\_post**() is async-signal-safe: it may be safely called within a signal handler.

## EXAMPLES

See [**sem\_wait**(3)](/sem_wait/3.md) and [**shm\_open**(3)](/shm_open/3.md).

## SEE ALSO

[**sem\_getvalue**(3)](/sem_getvalue/3.md), [**sem\_wait**(3)](/sem_wait/3.md), [**sem\_overview**(7)](/sem_overview/7.md), [**signal-safety**(7)](/signal-safety/7.md)
