SEM_DESTROY(3POSIX)

πŸ’… SEM_DESTROY(3POSIX) πŸ’…

okay bestie, welcome to the POSIX Programmer's Manual β€” yes this is SEM_DESTROY(3POSIX), and yes it's about semaphores, and yes we're gonna make it make sense. πŸŽ€

lowkey important heads-up before anything else: this page lives in the POSIX Programmer's Manual, and the Linux implementation of this interface may differ β€” so pls consult the corresponding Linux manual page for the actual Linux behavior. also possible: the interface might not even be implemented on Linux at all. πŸ™ˆ check before you ship, fr fr.

✨ NAME ✨

sem_destroy β€” destroy an unnamed semaphore 🫢


🌸 SYNOPSIS 🌸

#include <semaphore.h>

int sem_destroy(sem_t *sem);

πŸ¦‹ DESCRIPTION πŸ¦‹

so, sem_destroy() destroys the unnamed semaphore indicated by sem. that's the whole vibe. πŸ’–

now here's the tea, and it's important tea: only a semaphore that was created using sem_init() may be destroyed using sem_destroy(). if you call sem_destroy() on a named semaphore? the effect is undefined. not "probably fine", not "works on my machine" β€” undefined. 🚫

also, after you destroy it, using sem again is undefined until it gets reinitialized by another call to sem_init(). so like... it's giving ✨gone✨ until you bring it back properly.

it is safe to destroy an initialized semaphore when no threads are currently blocked on it. πŸ‘‘

but the effect of destroying a semaphore while other threads are currently blocked on it? undefined. do not do that. that's not main character energy, that's a crash arc. πŸ’€


🌈 RETURN VALUE 🌈

  • on a successful completion, a value of zero shall be returned. slay. ✨
  • otherwise, a value of -1 shall be returned and errno gets set to indicate the error. 😭

πŸ’œ ERRORS πŸ’œ

the sem_destroy() function may fail if:

  • EINVAL β€” the sem argument is not a valid semaphore. 🚩
  • EBUSY β€” there are currently processes blocked on the semaphore. 😬
ngl bestie, the following sections are informative. so like, they're context, not gospel. πŸ“–

πŸŽ€ EXAMPLES πŸŽ€

None. πŸ’…


πŸ“ APPLICATION USAGE πŸ“

None. 🫢


🧚 RATIONALE 🧚

None. ✨


⭐ FUTURE DIRECTIONS ⭐

None. 🌸


πŸ‘‘ SEE ALSO πŸ‘‘

  • semctl()
  • semget()
  • semop()
  • sem_init()
  • sem_open()

also the Base Definitions volume of POSIX.1‐2017, <semaphore.h> πŸ“š


okay legal moment, stay with me, this part matters:

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie πŸ₯Ή this has been IEEE/The Open Group, 2017, signing off from SEM_DESTROY(3POSIX). go destroy ur semaphores responsibly, mwah πŸ’‹πŸ’…βœ¨