sema_trywait

Makes a single attempt to acquire the resource protected by a semaphore.

Library:LibC
Classification:UNIX International
Service:Synchronization

Syntax

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

Parameters

sp

(IN) Points to the semaphore to acquire.

Return Values

If successful in acquiring the semaphore, returns 1 (TRUE); otherwise returns 0 (FALSE).

Remarks

If the semaphore count is greater than zero, sem_trywait decrements the semaphore value and returns TRUE to indicate a successful acquisition of the resource. If the semaphore value is less than or equal to zero, the semaphore cannot be immediately acquired. Because sem_trywait cannot block and wait for the resource to become available, the function returns FALSE to indicate failure and does not modify the semaphore value.

See Also