pthread_condattr_getclock, pthread_condattr_setclock Subroutine

Purpose

Gets and sets the clock selection condition variable attribute.

Syntax

 int pthread_condattr_getclock(const pthread_condattr_t *restrict attr,
       clockid_t *restrict clock_id);
int pthread_condattr_setclock(pthread_condattr_t *attr,
       clockid_t clock_id);

Description

The pthread_condattr_getclock subroutine obtains the value of the clock attribute from the attributes object referenced by the attr argument. The pthread_condattr_setclock subroutine sets the clock attribute in an initialized attributes object referenced by the attr argument. If pthread_condattr_setclock is called with a clock_id argument that refers to a CPU-time clock, the call will fail.

The clock attribute is the clock ID of the clock that shall be used to measure the timeout service of the pthread_cond_timedwait subroutine. The default value of the clock attribute refers to the system clock.

Parameters

Item Description
attr Specifies the condition attributes object.
clock_id For pthread_condattr_getclock(), points to where the clock attribute value will be stored.For pthread_condattr_setclock(), specifies the clock to set. Valid values are:
CLOCK_REALTIME
The system realtime clock.
CLOCK_MONOTONIC
The system monotonic clock. The value of this clock represents the amount of time since an unspecified point in the past. The value of this clock always grows: it cannot be set by clock_settime() and cannot have backward clock jumps.

Return Values

If successful, the pthread_condattr_getclock subroutine returns 0 and stores the value of the clock attribute of attr in the object referenced by the clock_id argument. Otherwise, an error code is returned to indicate the error.

If successful, the pthread_condattr_setclock subroutine returns 0; otherwise, an error code is returned to indicate the error.

Error Codes

Item Description
EINVAL The value specified by attr is invalid.
EINVAL The pthread_condattr_setclock subroutine returns this error if the value specified by the clock_id does not refer to a known clock, or is a CPU-time clock.
ENOTSUP The function is not supported with checkpoint-restart processes.