1SEM_DESTROY(3) Linux Programmer's Manual SEM_DESTROY(3)
2
3
4
6 sem_destroy - destroy an unnamed semaphore
7
9 #include <semaphore.h>
10
11 int sem_destroy(sem_t *sem);
12
13 Link with -pthread.
14
16 sem_destroy() destroys the unnamed semaphore at the address pointed to
17 by sem.
18
19 Only a semaphore that has been initialized by sem_init(3) should be
20 destroyed using sem_destroy().
21
22 Destroying a semaphore that other processes or threads are currently
23 blocked on (in sem_wait(3)) produces undefined behavior.
24
25 Using a semaphore that has been destroyed produces undefined results,
26 until the semaphore has been reinitialized using sem_init(3).
27
29 sem_destroy() returns 0 on success; on error, -1 is returned, and errno
30 is set to indicate the error.
31
33 EINVAL sem is not a valid semaphore.
34
36 For an explanation of the terms used in this section, see
37 attributes(7).
38
39 ┌──────────────┬───────────────┬─────────┐
40 │Interface │ Attribute │ Value │
41 ├──────────────┼───────────────┼─────────┤
42 │sem_destroy() │ Thread safety │ MT-Safe │
43 └──────────────┴───────────────┴─────────┘
45 POSIX.1-2001, POSIX.1-2008.
46
48 An unnamed semaphore should be destroyed with sem_destroy() before the
49 memory in which it is located is deallocated. Failure to do this can
50 result in resource leaks on some implementations.
51
53 sem_init(3), sem_post(3), sem_wait(3), sem_overview(7)
54
56 This page is part of release 4.15 of the Linux man-pages project. A
57 description of the project, information about reporting bugs, and the
58 latest version of this page, can be found at
59 https://www.kernel.org/doc/man-pages/.
60
61
62
63Linux 2017-09-15 SEM_DESTROY(3)