Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!brl-adm!rutgers!princeton!puvax2!PUCC.BITNET!D0430 From: D0430@PUCC.BITNET (Paul Lansky) Newsgroups: comp.unix.wizards Subject: beating time Message-ID: <1346@PUCC.BITNET> Date: Tue, 11-Nov-86 22:41:07 EST Article-I.D.: PUCC.1346 Posted: Tue Nov 11 22:41:07 1986 Date-Received: Wed, 12-Nov-86 02:23:35 EST Reply-To: D0430@PUCC.BITNET Organization: Princeton University Computing Center, Princeton, New Jersey Lines: 38 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 #include #include 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@pucc Music Department uucp == princeton!winnie!paul Princeton University