chsvlib
chsv helper source code

◆ chsv_cnd_timedwaitfor()

int Chusov::ExecutionControl::chsv_cnd_timedwaitfor ( chsv_cnd_t pCnd,
chsv_mtx_t pMtx,
unsigned long  cMilliseconds 
)
noexcept

Atomically unlocks the specified mutex and endeavours to block until the specified condition variable is signalled by a call to chsv_cnd_signal or to chsv_cnd_broadcast, or until the specified time elapses.

Parameters
[in]pCndis a pointer to a descriptor of the condition variable object to be waited for.
[in]pMtxis a pointer to a mutex object to be atomically signalled before the waiting for the condition variable. When the condition variable is signalled so that the calling thread becomes unlocked, the thread atomically endeavours to lock the mutex with blocking. The mutex has to be owned by the calling thread before the call. Otherwise the function will abort execution of the whole program by calling the abort function.
[in]cMillisecondsis a whole number of milliseconds for the function to wait for the condition variable to be signalled.
Returns
On success the function returns chsv_thrd_success. The function can also fail with chsv_thrd_timeout if the time specified was reached without acquiring the resource, or chsv_thrd_error if the request could not be honoured because of any other error. In these case the failure reason is also specified by the errno code the function sets.

This is an extension to the chsv_cnd_timedwait function which implements waiting for an absolute time specified as chsv_xtime object as specified by the C11 standard. The chsv_cnd_timedwaitfor function uses a relative time passed since the moment of a call.

On POSIX systems (see the IEEE Str 1003.1 standard) the implementation sometimes spurious wakeups of threads, blocked while waiting for the condition variable, may occur. The function does not handle these wakeups and it is up to the caller to verify them.

See also
chsv_cnd_signal;
chsv_cnd_broadcast;
chsv_cnd_wait;
chsv_cnd_timedwaitfor.