sem_getvalue

Returns the value of a semaphore.

Library:LibC
Classification:POSIX
Service:Synchronization

Syntax

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

Parameters

sem

(IN) Points to the semaphore.

value

(OUT) Points to the value of the semaphore.

Return Values

If successful, returns zero; otherwise, returns -1 and sets errno to one of the following values:

Decimal

Constant

Description

9

EINVAL

The sem parameter is invalid.

Remarks

The sem_getvalue function returns a value that was current at some time during the call, but this value is not guaranteed to still be current when the call returns. If the semaphore is locked, the value returned is either 0 or a negative number representing the number of processes that were waiting for the semaphore at some time during the call.

See Also