cynchronised sleep capbilty..
Peter Edwards
peadar.edwards at gmail.com
Wed Feb 2 02:44:35 PST 2005
On Tue, 1 Feb 2005 13:20:15 -0800 (PST), Julian Elischer
<julian at elischer.org> wrote:
>
>
> On Wed, 2 Feb 2005, Peter Jeremy wrote:
>
> > On Tue, 2005-Feb-01 10:20:24 -0800, Julian Elischer wrote:
> > >while:
> > >do
> > > report results
> > > sleep -until_next 10
> > >done
> >
> > How about:
> > 1) Re-write the loop in C, perl or equivalent using setitimer(). You
> > can system() out to collect the results.
> > 2) <kludge>Write a small C program that uses setitimer() and signals
> > its parent whenever the timer triggers. Run it in the background
> > and just pause within the sh loop.</kludge>
> >
> >
>
> this is what I ended up doing..
>
> # like sleep 10 except that it phase locks to teh 10 second boundary
> # so that multiple machines are talking about the same sample period.
I do something similar in C that requires no long-term drift, but it's
a little more general: Use an absolute time for sleeps, rather than
relative to "now". e.g.:
time_t wakeup = time(0);
while (!done) {
// avoid multiple firings if "dostuff()" takes longer than interval
while (wakeup < time(0))
wakeup += interval;
sleepUntil(wakeup);
dostuff();
}
Where sleepUntil can be implemented either as a sleep relative to
wakeupTime - now, or use a pthreads function like
pthread_cond_timedwait(), for example. The shell code would probably
be equally simple
More information about the freebsd-current
mailing list