sem_destroy()--Destroy Unnamed Semaphore


  Syntax
 #include <semaphore.h>

 int sem_destroy(sem_t * sem); 

  Service Program Name: QP0ZPSEM

  Default Public Authority: *USE

  Threadsafe: Yes

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.


Parameters

sem
(Input) A pointer to an initialized unnamed semaphore. The semaphore is destroyed.

Authorities

None.


Return Value

0 sem_destroy() was successful.
-1 sem_destroy() was not successful. The errno variable is set to indicate the error.


Error Conditions

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.

[EBUSY]

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.

[EINVAL]

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.


Error Messages

None.


Related Information


Example

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().

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <semaphore.h>
main() {
  sem_t my_semaphore;
  int rc;

  rc = sem_init(&my_semaphore, 0, 10);
  rc = sem_destroy(&my_semaphore);
}


API introduced: V4R4

[ Back to top | UNIX-Type APIs | APIs by category ]