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, -1 is returned, and errno is 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 โ€” sem is not a valid semaphore. it's giving "who even are you" ๐Ÿšซ
  • EOVERFLOW โ€” the value would exceed SEM_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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms