Name

sem_getvalue
- get the value of a semaphore

Library

libpthread.lib

Synopsis

  #include <semaphore.h>
  int sem_getvalue (sem_t * sem, int * sval);

Return values

Upon successful completion, function return a value of zero. Otherwise, it shall return a value of -1 and set errno to indicate the error.

Detailed description

The sem_getvalue function sets the variable pointed to by sval to the current value of the semaphore pointed to by sem, as of the time that the call to sem_getvalue is actually run.

Examples

sem_t psem;   
int val;
if (sem_init(&psem, 0, 1) < 0) {
        perror("sem_init");
        return -1;
   }
if( sem_getvalue(psem, &val) == -1 ) {
  perror("sem_getvalue failed");
  return -1;
 }


Errors

The sem_getvalue function will fail if:
[EINVAL]
  The sem argument points to an invalid semaphore.

See also

sem_post, sem_trywait in sem_wait


Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top