sem_post(3)
โจ sem_post(3) โ bestie's guide to unlocking a semaphore โจ
okay so real quick, this is a page from the Library Functions Manual and it's about sem_post(3), the little function that goes ding ๐ and lets the next gorl into the club. pull up a chair ๐
๐ NAME
sem_post โ unlock a semaphore
no fr that's it. that's the whole job. it unlocks the semaphore. icon behavior ๐
๐ LIBRARY
POSIX threads library โ that's libpthread, and you link it with -lpthread. periodt.
๐ธ SYNOPSIS
#include <semaphore.h>
int sem_post(sem_t *sem);
look at her. one include, one call, zero drama ๐ฆ
๐ DESCRIPTION
so sem_post() increments (aka unlocks) the semaphore that sem points to. that's the vibe.
and here's the juicy part bestie: if the semaphore's value becomes greater than zero after that increment, then some other process or thread that's been sitting there blocked in a sem_wait(3) call gets woken up and proceeds to lock the semaphore. she was waiting in the queue, you opened the door, she walks in. main character handoff ๐คโจ
๐ซถ RETURN VALUE
- on success โ
0. slay. - on error โ the value of the semaphore is left unchanged,
-1is returned, anderrnois set to tell you what went wrong.
okay lowkey important: on error the semaphore value stays exactly what it was. no half-updated nonsense. she's respectful like that ๐
๐ ERRORS
EINVALโsemis not a valid semaphore. it's giving "who even are you" ๐ซEOVERFLOWโ the value would exceedSEM_VALUE_MAX. too much. overflowing. the semaphore said "no more, I'm full" ๐ญ
๐ ATTRIBUTES
for the tea on what all these terms mean, go read attributes(7).
- Interface:
sem_post()- Attribute: Thread safety
- Value:
MT-Safeโ
translation: she's safe to call from multiple threads. no cap.
๐ STANDARDS
POSIX.1-2008. she's certified, babes ๐
๐ฆ HISTORY
POSIX.1-2001. she's been here, she's been iconic, she's been doing this ๐
๐ฅ NOTES
sem_post() is async-signal-safe: it may be safely called within a signal handler.
this is a big deal actually!! you can call her inside a signal handler and nothing bad happens. she's that gorl ๐
๐ EXAMPLES
See sem_wait(3) and shm_open(3). they got the receipts, go peek ๐
๐ SEE ALSO
okay that's the whole page bestie, you're officially semaphore-literate ๐โจ this was Linux man-pages 6.20, dated 2026-02-08, and she ate, no crumbs left. go unlock something ๐
๐ซถ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2006, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms