#include <semaphore.h>
int sem_post_np(sem_t * sem,
sem_post_options_np_t *options);
|
The sem_post_np() function posts to a semaphore, incrementing its value by the increment specified in the options parameter. If the resulting value is greater than zero and if there are threads waiting on the semaphore, the waiting threads decrement the semaphore and continue running.
Parameters
The members of the sem_post_options_np_t structure are as follows.
Authorities
None
Return Value
Error Conditions
If sem_post_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.
Posting to the semaphore would cause its value to exceed its maximum value. The maximum value is SEM_VALUE_MAX or was set using sem_open_np() or sem_init_np().
The reserved fields of the attr argument are not set to zero.
Error Messages
None.
Related Information
Example
The following example initializes an unnamed semaphore and posts to it, incrementing its value by 2.
#include <stdio.h>
#include <semaphore.h>
main() {
sem_t my_semaphore;
sem_post_options_np_t options;
int value;
sem_init(&my_semaphore, 0, 10);
sem_getvalue(&my_semaphore, &value);
printf("The initial value of the semaphore is %d.\n", value);
memset(&options, 0, sizeof(options));
options.increment=2;
sem_post_np(&my_semaphore,&options);
sem_getvalue(&my_semaphore, &value);
printf("The value of the semaphore after the post is %d.\n", value);
}
Output:
The initial value of the semaphore is 10. The value of the semaphore after the post is 12.
| Top | Interprocess Communication APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |