sem_trywait()

Wait on a named or unnamed semaphore, but don't block

Synopsis:

#include <semaphore.h>

int sem_trywait( sem_t * sem );

Arguments:

sem
A pointer to the sem_t object for the semaphore that you want to wait on.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The sem_trywait() function decrements the semaphore if the semaphore's value is greater than zero; otherwise, the function simply returns.

Returns:

0
The semaphore was successfully decremented.
-1
The state of the semaphore is unchanged (errno is set).

Errors:

EAGAIN
The count wasn't greater then 0, so sem_trywait() couldn't immediately decrement it.
EINVAL
Invalid semaphore descriptor sem.
EINTR
A signal interrupted this function.

Classification:

POSIX 1003.1

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