#include <semaphore.h>
int sem_init(sem_t * sem, int shared,
unsigned int value);
|
The sem_init() function initializes an unnamed semaphore and sets its initial value. The maximum value of the semaphore is set to SEM_VALUE_MAX. The title for the semaphore is set to the character representation of the address of the semaphore. If an unnamed semaphore already exists at sem, then it will be destroyed and a new semaphore will be initialized.
Parameters
Authorities
None
Return Value
Error Conditions
If sem_init() 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 value parameter is greater than SEM_VALUE_MAX.
System semaphore resources have been exhausted.
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. Its value is set to 10.
#include <semaphore.h>
main() {
sem_t my_semaphore;
int rc;
rc = sem_init(&my_semaphore, 0, 10);
}
| Top | Interprocess Communication APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |