1SEM_DESTROY(3)             Linux Programmer's Manual            SEM_DESTROY(3)
2
3
4

NAME

6       sem_destroy - destroy an unnamed semaphore
7

SYNOPSIS

9       #include <semaphore.h>
10
11       int sem_destroy(sem_t *sem);
12
13       Link with -pthread.
14

DESCRIPTION

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 de‐
20       stroyed 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

RETURN VALUE

29       sem_destroy() returns 0 on success; on error, -1 is returned, and errno
30       is set to indicate the error.
31

ERRORS

33       EINVAL sem is not a valid semaphore.
34

ATTRIBUTES

36       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
37       tributes(7).
38
39       ┌────────────────────────────────────────────┬───────────────┬─────────┐
40Interface                                   Attribute     Value   
41       ├────────────────────────────────────────────┼───────────────┼─────────┤
42sem_destroy()                               │ Thread safety │ MT-Safe │
43       └────────────────────────────────────────────┴───────────────┴─────────┘
44

CONFORMING TO

46       POSIX.1-2001, POSIX.1-2008.
47

NOTES

49       An  unnamed semaphore should be destroyed with sem_destroy() before the
50       memory in which it is located is deallocated.  Failure to do  this  can
51       result in resource leaks on some implementations.
52

SEE ALSO

54       sem_init(3), sem_post(3), sem_wait(3), sem_overview(7)
55

COLOPHON

57       This  page  is  part of release 5.13 of the Linux man-pages project.  A
58       description of the project, information about reporting bugs,  and  the
59       latest     version     of     this    page,    can    be    found    at
60       https://www.kernel.org/doc/man-pages/.
61
62
63
64Linux                             2021-03-22                    SEM_DESTROY(3)
Impressum