Debian Codegraph @

upstream/debian-trixie/man3/sem_destroy.3

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