sem_getvalue(3pthread)


sem_getvalue -- get the value of a semaphore

Synopsis

   cc [options] -Kthread file
   

#include <semaphore.h>

int sem_getvalue(sem_t *sem, int *sval);

Description

sem_getvalue updates the location referenced by sval to have the value of the semaphore referenced by sem without affecting the state of the semaphore. The updated value represents an actual semaphore value that occurred at some unspecified time during the call, but it need not be the actual value of the semaphore when it is returned to the calling process.

If sem is locked, then the value returned by sem_getvalue is either zero or a negative number whose absolute value represents the number of threads waiting for the semaphore at some unspecified time during the call.

Return values

sem_getvalue returns a value of zero on success. Otherwise, it returns a value of -1 and sets errno to indicate the error.

Diagnostics

If the following conditions are detected, sem_getvalue returns the corresponding value:

EINVAL
sem does not refer to a valid semaphore.

Standards compliance

The Single UNIX Specification, Version 2; The Open Group.

References

sem_post(3pthread), sem_trywait(3pthread), sem_wait(3pthread), semaphore(4)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004