#include <semaphore.h>
int sem_init_np(sem_t * sem, int shared,
unsigned int value,
sem_attr_np_t * attr);
|
The sem_init_np() function initializes an unnamed semaphore and sets its initial value. The sem_init_np() function uses the attr parameter to set the maximum value and title of the semaphore. If an unnamed semaphore already exists at sem, then it will be destroyed and a new semaphore will be initialized.
Parameters
The members of the sem_attr_np_t structure are as follows.
Authorities
None
Return Value
Error Conditions
If sem_init_np() 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 the maxvalue field of the attr parameter.
The maxvalue field of the attr parameter is greater than SEM_VALUE_MAX.
The maxvalue field of the attr parameter is equal to zero.
The reserved fields of the attr argument are not set to zero.
In attempting to use an argument in a call, the system detected an address that is not valid.
While attempting to access a parameter passed to this function, the system detected an address that is not valid.
The requested operations required additional space on the device and there is no space left. This could also be caused by exceeding the user profile storage limit when creating or transferring ownership of an object.
Insufficient space remains to hold the intended file, directory, or link.
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 and sets its value to 10. The maximum value and title of the semaphore are set to 10 and "MYSEM".
#include <semaphore.h>
main() {
sem_t my_semaphore;
sem_attr_np_t attr;
int rc;
memset(&attr, 0, sizeof(attr));
attr.maxvalue = 10;
strcpy(attr.title, "MYSEM");
rc = sem_init_np(&my_semaphore, 0, 10, &attr);
}
| Top | Interprocess Communication APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |