sem_destroy(3)

sem_destroy3

Destroy an unnamed semaphore

Usage

#include <semaphore.h>

int

sem_destroy(sem_t *sem);

Library

Standard C Library (libc, -lc)

Overview

The sem_destroy() function destroys the unnamed semaphore pointed to by sem. After a successful call to sem_destroy(), sem is unusable until re-initialized by another call to sem_init(3).

Return values

The sem_destroy() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Errors

The sem_destroy() function will fail if:

[EINVAL]

The sem argument points to an invalid semaphore.

[EBUSY]

There are currently threads blocked on the semaphore that sem points to.

Releases

70 releases since FreeBSD 4.0-RELEASE; the text changed 40 times.

  1. 4.0
  2. 4.1–4.2
  3. 4.3
  4. 4.4
  5. 4.5–4.7
  6. 4.8–4.11
  7. 5.0
  8. 5.1–5.2.1
  9. 5.3–6.3
  10. 6.4
  11. 7.0
  12. 7.1
  13. 7.2
  14. 7.3
  15. 7.4
  16. 8.0
  17. 8.1
  18. 8.2
  19. 8.3
  20. 8.4
  21. 9.0
  22. 9.1
  23. 9.2
  24. 9.3
  25. 10.0
  26. 10.1
  27. 10.2
  28. 10.3
  29. 10.4
  30. 11.0
  31. 11.1
  32. 11.2
  33. 11.3
  34. 11.4
  35. 12.0
  36. 12.1
  37. 12.2
  38. 12.3
  39. 12.4
  40. 13.0–13.2
  41. 13.3–16.0

Standards

The sem_destroy() function conforms to ISO/IEC 9945-1:1996 (“POSIX.1”).

POSIX does not define the behavior of sem_destroy() if called while there are threads blocked on sem, but this implementation is guaranteed to return -1 and set errno to EBUSY if there are threads blocked on sem.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.