#include <semaphore.h> int sem_destroy(sem_t * sem);
The sem_destroy() function destroys an unnamed semaphore that was previously initialized using sem_init() or sem_init_np(). Any threads that have blocked from calling sem_wait() or sem_wait_np() on the semaphore will unblock and return an [EINVAL] or [EDESTROYED] error.
None
0 | sem_destroy() was successful. |
-1 | sem_destroy() was not successful. The errno variable is set to indicate the error. |
If sem_destroy() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Resource busy.
An attempt was made to use a system resource that is not available at this time.
The semaphore is being destroyed by another thread.
The value specified for the argument is not correct.
A function was passed incorrect argument values, or an operation was attempted on an object and the operation specified is not supported for that type of object.
An argument value is not valid, out of range, or NULL.
The sem parameter is not a valid semaphore.
None.
See Code disclaimer information for information pertaining to code examples.
The following example initializes an unnamed semaphore, my_semaphore, that will be used by threads of the current process and sets its value to 10. The semaphore is then destroyed using sem_destroy().
#include <semaphore.h> main() { sem_t my_semaphore; int rc; rc = sem_init(&my_semaphore, 0, 10); rc = sem_destroy(&my_semaphore); }
Top | UNIX-Type APIs | APIs by category |