Performs a semaphore lock.
This function is supported on OpenVMS Integrity servers and
Alpha only.
Format
#include <semaphore.h>
#include <time.h>
int sem_timedwait (sem_t *sem, const struct timespec
*abs_timeout);
1 – Argument
sem
The semaphore to be locked.
abs_timeout
The absolute time after which the timeout expires.
2 – Description
The sem_timedwait function locks the semaphore referenced by
sem as in the sem_wait function. But if the semaphore cannot be
locked without waiting for another process or thread to unlock
the semaphore by performing a sem_post function, this wait
terminates when the specified timeout expires.
The timeout expires when the absolute time specified by abs_
timeout passes, as measured by the clock on which timeouts are
based (that is, when the value of that clock equals or exceeds
abs_timeout, or if the absolute time specified by abs_timeout has
already been passed at the time of the call.
The function will not fail with a timeout if the semaphore can be
locked immediately. The validity of abs_timeout does not need to
be checked if the semaphore can be locked immediately.
3 – Return Values
0 Successful completion. The function executes
the semaphore lock operation.
-1 Indicates an error. The function sets errno to
one of the following values:
o ETIMEDOUT - The semaphore could not
be locked before the specified timeout
expired.
o EINVAL - The sem argument does not refer to
a valid semaphore. Or the process or thread
would have blocked, and the abs_timeout
parameter specified a nanoseconds field
value less than zero or greater than or
equal to 1000 million.
o EVMSERR - OpenVMS specific nontranslatable
error code.