[Previous] [Contents] [Index] [Next]

sem_getvalue()

Get the value of a semaphore (named or unnamed)

Synopsis:

#include <semaphore.h>

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

Library:

libc

Description:

The sem_getvalue() function takes a snapshot of the value of the semaphore, sem and stores it in value. This value can change at any time, and is guaranteed valid only at some point in the sem_getvalue() call.

This function is provided for debugging semaphore code.

The semaphore value indicates information about the semaphore:

Semaphore value is... and means...
> 0 (positive) the semaphore is unlocked
0 (zero) the semaphore is locked

Returns:

0
Success. The semaphore value is stored in value.
-1
An error occurred (errno is set).

Errors:

EINVAL
Invalid semaphore descriptor sem.

Classification:

POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

sem_destroy(), sem_init(), sem_trywait(), sem_wait()


[Previous] [Contents] [Index] [Next]