sem_timedwait()

lock a semaphore 

Realtime Function


SYNOPSIS

SYNOPSIS

#include <semaphore.h>

#include <time.h>

int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict abs_timeout);


DESCRIPTION

The sem_timedwait() function locks the specified semaphore as in the sem_wait() function. However, if the specified semaphore needs to be unlocked by another thread or process (with sem_post()) before it can be locked, the sem_timedwait() function only waits for this unlock until the timeout expires.

The timeout expires after the amount of time specified by abs_timeout passes or if the specified amount of time has already passed at the time of the call.

The timespec data type is defined as a structure in the <time.h> header.

If the semaphore can be locked immediately, the abs_timeout argument is ignored.


PARAMETERS

sem 

Specifies the semaphore to be locked.

abs_timeout 

Specifies how long to wait for the semaphore to become unlocked by another thread or process.


RETURN VALUES

When successful, the sem_timedwait() function returns zero. Otherwise, the state of the semaphore is unchanged, the function returns -1, and errno is set to one of the following values:

EINTR 

A signal interrupted this function.

EINVAL 

The sem argument is not a valid semaphore.

EINVAL 

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.

ETIMEDOUT 

The semaphore could not be locked before the specified timeout expired.


EXAMPLES

None.


CONFORMANCE

UNIX 03. Derived from IEEEĀ StdĀ 1003.1d-1999.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

On the NuTCRACKER Platform, the timeout is handled by Win32 functions and is less precise than on UNIX platforms. On UNIX platforms with the Timers option supported, the timeout is based on the CLOCK_REALTIME clock. On UNIX platforms without the Timers option, the timeout is based on the system clock as returned by the time() function. In either case, the resolution of the timeout is the same as the resolution of the clock on which it is based.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
sem_post(), sem_trywait(), sem_wait(), semctl(), semget(), semop(), time()

Miscellaneous:
semaphores


PTC MKS Toolkit 10.4 Documentation Build 39.