| 1 |
'\" t |
| 2 |
.\" Copyright 2006, Michael Kerrisk <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH sem_destroy 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
sem_destroy \- destroy an unnamed semaphore |
| 10 |
.SH LIBRARY |
| 11 |
POSIX threads library |
| 12 |
.RI ( libpthread ,\~ \-lpthread ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <semaphore.h> |
| 16 |
.P |
| 17 |
.BI "int sem_destroy(sem_t *" sem ); |
| 18 |
.fi |
| 19 |
.SH DESCRIPTION |
| 20 |
.BR sem_destroy () |
| 21 |
destroys the unnamed semaphore at the address pointed to by |
| 22 |
.IR sem . |
| 23 |
.P |
| 24 |
Only a semaphore that has been initialized by |
| 25 |
.BR sem_init (3) |
| 26 |
should be destroyed using |
| 27 |
.BR sem_destroy (). |
| 28 |
.P |
| 29 |
Destroying a semaphore that other processes or threads are |
| 30 |
currently blocked on (in |
| 31 |
.BR sem_wait (3)) |
| 32 |
produces undefined behavior. |
| 33 |
.P |
| 34 |
Using a semaphore that has been destroyed produces undefined results, |
| 35 |
until the semaphore has been reinitialized using |
| 36 |
.BR sem_init (3). |
| 37 |
.SH RETURN VALUE |
| 38 |
.BR sem_destroy () |
| 39 |
returns 0 on success; |
| 40 |
on error, \-1 is returned, and |
| 41 |
.I errno |
| 42 |
is set to indicate the error. |
| 43 |
.SH ERRORS |
| 44 |
.TP |
| 45 |
.B EINVAL |
| 46 |
.I sem |
| 47 |
is not a valid semaphore. |
| 48 |
.SH ATTRIBUTES |
| 49 |
For an explanation of the terms used in this section, see |
| 50 |
.BR attributes (7). |
| 51 |
.TS |
| 52 |
allbox; |
| 53 |
lbx lb lb |
| 54 |
l l l. |
| 55 |
Interface Attribute Value |
| 56 |
T{ |
| 57 |
.na |
| 58 |
.nh |
| 59 |
.BR sem_destroy () |
| 60 |
T} Thread safety MT-Safe |
| 61 |
.TE |
| 62 |
.SH STANDARDS |
| 63 |
POSIX.1-2008. |
| 64 |
.SH HISTORY |
| 65 |
POSIX.1-2001. |
| 66 |
.SH NOTES |
| 67 |
An unnamed semaphore should be destroyed with |
| 68 |
.BR sem_destroy () |
| 69 |
before the memory in which it is located is deallocated. |
| 70 |
Failure to do this can result in resource leaks on some implementations. |
| 71 |
.\" But not on NPTL, where sem_destroy () is a no-op.. |
| 72 |
.SH SEE ALSO |
| 73 |
.BR sem_init (3), |
| 74 |
.BR sem_post (3), |
| 75 |
.BR sem_wait (3), |
| 76 |
.BR sem_overview (7) |