sem_destroy Subroutine

Purpose

Destroys an unnamed semaphore.

Library

Standard C Library (libc.a)

Syntax

#include <semaphore.h>

int sem_destroy (sem)
sem_t *sem;

Description

The sem_destroy subroutine destroys the unnamed semaphore indicated by the sem parameter. Only a semaphore that was created using the sem_init subroutine can be destroyed using the sem_destroy subroutine; calling sem_destroy with a named semaphore returns an error. Subsequent use of the semaphore sem returns an error until sem is reinitialized by another call to sem_init. It is safe to destroy an initialized semaphore upon which other threads are currently blocked.

Parameters

Item Description
sem Indicates the semaphore to be closed.

Return Values

Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno set to indicate the error.

Error Codes

The sem_destroy subroutine fails if:
Item Description
EACCES Permission is denied to destroy the unnamed semaphore.
EFAULT Invalid user address.
EINVAL The sem parameter is not a valid semaphore.
ENOTSUP This function is not supported with processes that have been checkpoint-restart'ed.