DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

sem_close(3pthread)


sem_close -- close a named semaphore

Synopsis

   cc [options] -Kthread file
   

#include <semaphore.h>

int sem_close(sem_t *sem);

Description

sem_close is used to indicate that the calling process is finished using the named semaphore sem (created by sem_open). The effects of calling sem_close for an unnamed semaphore (one created by sem_init) are undefined.

sem_close deallocates any system resources allocated by the system for use by this process for this semaphore. (That is, it makes them available for reuse by a subsequent sem_open by this process.) If the semaphore has not been removed with a successful call to sem_unlink, then sem_close has no effect on the state of the semaphore. If sem_unlink has been successfully invoked for name after the most recent call to sem_open with the O_CREAT flag for this semaphore, then when all processes that have opened the semaphore close it, the semaphore is no longer accessible.

Return values

sem_close returns zero on success. Otherwise, a value of -1 is returned and errno is set to indicate the error.

Diagnostics

sem_close returns the following value if the corresponding condition is detected:

EINVAL
The sem argument is not a valid semaphore descriptor.

Standards compliance

The Single UNIX Specification, Version 2; The Open Group.

References

Intro(3pthread), sem_init(3pthread), sem_open(3pthread), sem_unlink(3pthread), semaphore(4)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004