beating time
Paul Lansky
D0430 at PUCC.BITNET
Wed Nov 12 13:41:07 AEST 1986
Can someone tell me why the following short program keeps such lousy
time? (metronome emulator) I tried it under Ultrix 1.1 and 4.2.
I would expect some granularity but not to the extent I saw. With an
argument of 1, for example, there are sometimes errors of as much as 50%
/* beats time according to command line argument */
#include <sys/time.h>
#include <sys/signal.h>
#include <stdio.h>
float tick,tval=0;
struct itimerval *value;
main(argc,argv)
char *argv[];
{
int beatit();
char *malloc();
double atof();
tick = atof(*++argv);
value = (struct itimerval *)malloc(sizeof(value));
value->it_value.tv_sec = value->it_interval.tv_sec = (int)tick;
value->it_value.tv_usec = value->it_interval.tv_usec = (int)(
1000000. * (tick - (float)value->it_value.tv_sec));
(void) signal(SIGALRM,beatit);
setitimer(ITIMER_REAL,value,value);
while(1);
}
beatit() {
getitimer(ITIMER_REAL,value);
tval += value->it_value.tv_sec + (float)value->it_value.tv_usec/1000000;
printf("%f"\n",tval);
}
thanks
Paul Lansky bitnet == d0430 at pucc
Music Department uucp == princeton!winnie!paul
Princeton University
More information about the Comp.unix.wizards
mailing list