control.wait


template <typename T>
inline auto wait(() -> T fn) §

Block the calling thread until a condition defined by the function fn is satisfied. The function fn is checked atomically in each cycle.

When T is bool, the thread is unblocked when fn returns true. Otherwise, if T is an instance of optional, the thread is unblocked when fn returns a valid optional. In this case, wait returns the value inside the optional.

The function fn may have side effects but it must not access memory. The more general wait_until function allows memory access within fn however it is more costly in terms of area and throughput.

Example
// Wait for the global variable `g_var` is greater than 16
wait([]()
{
    return g_var > 16;
});

// Wait for `g_var` is greater than 16, and retrieve the value of `g_var`
uint32 result = wait([]()
{
    return make_optional(g_var > 16, g_var);
});
template <typename T>
inline auto wait_until(() -> T fn) §

Block the calling thread until a condition defined by the function fn is satisfied. The function fn is checked atomically in each cycle.

When T is bool, the thread is unblocked when fn returns true. Otherwise, if T is an instance of optional, the thread is unblocked when fn returns a valid optional. In this case, wait_until returns the value inside the optional.

The function fn may have side effects and may access memory. The function is more costly than wait in terms of area and as the percentage of calls to fn which return false increases, throughput of wait_until decreases more than wait.

Example
wait_until([x]()
{
    return mem[2] > x;
});