Learn R Programming

nanonext (version 0.9.1)

timed_signal: Signal a Condition Variable After a Specified Time

Description

Creates a new thread which signals a condition variable after a specified time, causing its internal condition to increment by one (and threads waiting on the condition to wake).

Usage

timed_signal(cv, time, flag = TRUE)

Value

A 'thread', which is an external pointer to the created thread. The return value must be assigned to an object, otherwise the thread may be garbage collected before it has performed its purpose.

Arguments

cv

a 'conditionVariable',

time

integer number of milliseconds after which to signal the condition variable.

flag

[default TRUE] logical value whether to also set a flag in the 'conditionVariable'. This can help distinguish between different types of signal, and causes any subsequent wait or until to return FALSE instead of TRUE.

Details

Non-integer values for 'time' are coerced to integer, and the absolute value is taken (the sign is ignored). Non-numeric values are ignored, in which case the condition variable is signalled immediately.

Examples

Run this code
cv <- cv()
cv_value(cv)
start <- mclock()

s <- timed_signal(cv, time = 100L, flag = FALSE)
wait(cv) == TRUE
mclock() - start

s <- timed_signal(cv, time = 100L, flag = TRUE)
wait(cv) == FALSE
mclock() - start

Run the code above in your browser using DataLab