sem_wait

Acquires the resource protected by a semaphore, blocking if necessary.

Library:LibC
Classification:POSIX
Service:Synchronization

Syntax

  #include <semaphore.h>
   
  int  sem_wait  (
     sem_t   *sem );
  

Parameters

sem

(IN) Points to the semaphore to acquire.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following values.

Decimal

Constant

Description

9

EINVAL

The sem parameter is invalid.

Remarks

The sema_wait function decrements the semaphore value:

  • If the semaphore value is zero or greater, and the calling thread returns having acquired the resource.

  • If the semaphore value is negative, the calling thread blocks on the semaphore and waits until the resource is available.

See Also