1sem_destroy(3) Library Functions Manual sem_destroy(3)
2
3
4
6 sem_destroy - destroy an unnamed semaphore
7
9 POSIX threads library (libpthread, -lpthread)
10
12 #include <semaphore.h>
13
14 int sem_destroy(sem_t *sem);
15
17 sem_destroy() destroys the unnamed semaphore at the address pointed to
18 by sem.
19
20 Only a semaphore that has been initialized by sem_init(3) should be de‐
21 stroyed using sem_destroy().
22
23 Destroying a semaphore that other processes or threads are currently
24 blocked on (in sem_wait(3)) produces undefined behavior.
25
26 Using a semaphore that has been destroyed produces undefined results,
27 until the semaphore has been reinitialized using sem_init(3).
28
30 sem_destroy() returns 0 on success; on error, -1 is returned, and errno
31 is set to indicate the error.
32
34 EINVAL sem is not a valid semaphore.
35
37 For an explanation of the terms used in this section, see at‐
38 tributes(7).
39
40 ┌────────────────────────────────────────────┬───────────────┬─────────┐
41 │Interface │ Attribute │ Value │
42 ├────────────────────────────────────────────┼───────────────┼─────────┤
43 │sem_destroy() │ Thread safety │ MT-Safe │
44 └────────────────────────────────────────────┴───────────────┴─────────┘
45
47 POSIX.1-2008.
48
50 POSIX.1-2001.
51
53 An unnamed semaphore should be destroyed with sem_destroy() before the
54 memory in which it is located is deallocated. Failure to do this can
55 result in resource leaks on some implementations.
56
58 sem_init(3), sem_post(3), sem_wait(3), sem_overview(7)
59
60
61
62Linux man-pages 6.04 2023-03-30 sem_destroy(3)