#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.
The members of the sem_post_options_np_t structure are as follows.
unsigned int reserved1[1] | A reserved field that must be set to zero. |
unsigned int increment | The value, greater than zero, used to increment the semaphore. If the value specified causes the value of a semaphore to exceed its maximum value, sem_post_np() will fail by returning [EINVAL]. |
unsigned int reserved2[2] | A reserved field that must be set to zero. |
None
0 | sem_post_np() was successful. |
-1 | sem_post_np() was not successful. The errno variable is set to indicate the error. |
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.
The value specified for the argument is not correct.
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.
Maximum value exceeded.
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.
None.
See Code disclaimer information for information pertaining to code examples.
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); }
The initial value of the semaphore is 10. The value of the semaphore after the post is 12.
Top | UNIX-Type APIs | APIs by category |