#include <semaphore.h> int sem_close(sem_t * sem);
|
The sem_close() function closes a named semaphore that was previously opened by a thread of the current process using sem_open() or sem_open_np(). The sem_close() function frees system resources associated with the semaphore on behalf of the process. Using a semaphore after it has been closed will result in an error. A semaphore should be closed when it is no longer used. If a sem_unlink() was performed previously for the semaphore and the current process holds the last reference to the semaphore, then the named semaphore will be deleted and removed from the system.
Parameters
Authorities
No authorization is required. Authorization is verified during sem_open().
Return Value
Error Conditions
If sem_close() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
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 opens a named semaphore with an initial value of 10 and then closes it.
#include <semaphore.h>
main() {
sem_t * my_semaphore;
int rc;
my_semaphore = sem_open("/mysemaphore",
O_CREAT, S_IRUSR | S_IWUSR,
10);
sem_close(my_semaphore);
}
| Top | Interprocess Communication APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |