sem_destroy(3)
โจ sem_destroy(3) โ Library Functions Manual โจ
okay bestie, welcome to the sem_destroy(3) page from the Library Functions Manual ๐ this is the one where we say bye-bye to a semaphore, so let's get into it ๐ซถ
๐ซ NAME
sem_destroy โ destroy an unnamed semaphore ๐ธ
๐ LIBRARY
POSIX threads library โ you're linking libpthread, so pop -lpthread on that compile line, bestie ๐
๐ฆ SYNOPSIS
#include <semaphore.h>
int sem_destroy(sem_t *sem);
like... that's it. one function. one pointer. iconic behavior tbh ๐
๐ DESCRIPTION
so sem_destroy() destroys the unnamed semaphore sitting at the address that sem points to. that's the whole job. she's done. she's retiring ๐
now here's the tea: only a semaphore that was initialized by sem_init(3) should be destroyed using sem_destroy(). don't be out here destroying semaphores that came from somewhere else, that's not the vibe ๐
โ ๏ธ major warning, no cap: destroying a semaphore that other processes or threads are currently blocked on (like, blocked inside sem_wait(3)) produces undefined behavior. that is the scary kind of undefined. do not do it fr fr ๐ญ
and also: using a semaphore that has already been destroyed produces undefined results, until the semaphore gets reinitialized using sem_init(3). so like, once she's gone she's GONE, no haunting the living unless you properly bring her back โจ
๐ RETURN VALUE
- on success:
sem_destroy()returns0โ we love a clean win ๐ - on error:
-1is returned, anderrnois set to indicate the error ๐
๐ธ ERRORS
EINVALโsemis not a valid semaphore. wrong vibe. invalid. rejected ๐
๐ ATTRIBUTES
for an explanation of the terms used in this section, check out attributes(7) (iykyk).
- Interface:
sem_destroy() - Attribute: Thread safety
- Value:
MT-Safe๐
โญ STANDARDS
POSIX.1-2008. periodt โจ
๐ HISTORY
POSIX.1-2001. she's been around a while, a true veteran ๐
๐ง NOTES
an unnamed semaphore should be destroyed with sem_destroy() before the memory that it lives in gets deallocated. yes, before. the order matters, bestie ๐ซถ
โ ๏ธ failing to do this can result in resource leaks on some implementations. and leaks are not cute. leaks are the opposite of cute ๐ญ
๐ฅ SEE ALSO
and that's the whole page, my love ๐ this was Linux man-pages 6.20, dated 2026-02-08, dropping sem_destroy(3) into the group chat. go free that semaphore (but like, responsibly, and after everyone's unblocked) ๐โจ๐๐
๐ฆ 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