WvTimeStream causes select() to be true after a configurable number of milliseconds. Because programs using WvStream make no guarantees about how often select() will be called, WvTimeStream tries to adjust its timing to a correct _average_ number of milliseconds per tick.
For example, if ms_per_tick=100, WvTimeStream will tick 10 times in one second. However, there may be a few milliseconds of difference ("jitter") for each individual tick, due to random system delays.
/*
* A WvTimeStream example.
*
* This program should take exactly ten seconds to run, but
* tests how well the time stream handles being executed in bursts.
*/
#include "wvtimestream.h"
#include "wvlog.h"
#include <sys/time.h>
int main()
{
WvLog log("time", WvLog::Info);
WvTimeStream t;
int count;
log("Artificial burstiness - should take exactly 10 seconds\n");
t.set_timer(100);
for (count = 0; count < 100; count++)
{
if (!(count % 10)) log("\n");
while (!t.select(5*(100-count)))
;
t.callback();
log("%02s ", count);
}
return 0;
}