sema_wait

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

Library:LibC
Classification:UNIX International
Service:Synchronization

Syntax

  #include <synch.h>
   
  int   sema_wait   (
     sema_t   *sp );
  

Parameters

sp

(IN) Points to the semaphore to acquire.

Return Values

When successful, returns 0.

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