#include <semaphore.h>
int sem_close(sem_t *sem);
The sem_close() function closes the semaphore specified
by the sem argument when the calling process is finished with
it.
When a semaphore is closed, sem_close() frees up any
system resources allocated to be used by that semaphore. These resources are
then available for use by a subsequent invocation of the
sem_open() function.
Using the specified semaphore again (without reopening it) in the same
process results in the semaphore function failing with errno
set to EINVAL.
The sem_close() function does not affect the state of
the semaphore, unless you have previously removed the semaphore with
the sem_unlink() function.
If you have used sem_unlink() to remove the specified
semaphore (after the most recent sem_open() call with
O_CREAT for that semaphore), sem_close()
causes the semaphore to be closed by all processes that have opened it and
it can no longer be accessed.
Attempting to close an unnamed semaphore (that is, a semaphore created
by the sem_init() function) with this function
can result in heap corruption or freeing resources that were not
malloc()ed.
You should only use sem_close()
with semaphores created by sem_open() and only use
sem_destroy() with semaphores created with
sem_init().
- sem
-
Specifies the named semaphore to be closed.
When successful, sem_close() returns zero.
Otherwise, it returns -1 and sets errno to one of the following
values:
- EBUSY
-
There are currently processes blocked on the semaphore.
- EINVAL
-
The sem argument is not a valid semaphore descriptor.
None.
UNIX 03.
Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)
MT-Safe.
None.
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
- Functions:
- sem_init(), sem_open(), sem_unlink(), semctl(), semget(), semop()
- Miscellaneous:
- semaphores
PTC MKS Toolkit 10.4 Documentation Build 39.