[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Delay in millisecond

I have tested the following program:
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
int main(void)
  int i;
  struct timeval tv;
  struct timeval tv2;
  gettimeofday(&tv, NULL);
  printf("Time before: %d\n", (int)tv.tv_sec);
  for (i = 0; i < 1000; i++)
  gettimeofday(&tv2, NULL);
  printf("Time after: %d\n", (int)tv2.tv_sec);
  printf("Diff: %d\n", (int)tv2.tv_sec - (int)tv.tv_sec);

This program performs a 100 ms sleep 1000 times. The result is:
Diff: 110 
(in a perfect world with an infinite fast processor the expected result would
be 100).
Can you test the program above and see if you get the same result?
If you get the same result I need to know more about your problem.
How is your program different from the example above?

-----Original Message-----
From: owner-dev-etrax@xxxxxxx.com]On">mailto:owner-dev-etrax@xxxxxxx.com]On Behalf Of Nabil Daher
Sent: Tuesday, January 14, 2003 5:24 PM
To: dev-etrax
Subject: Delay in millisecond

I have a problem with usleep()....When the sleep delay is under 1 second, the function return immediatly without waiting... How can I use a delay with a 100 millisec resolution in user space?
I use a Devboard LX with 2.4.19 Kernel.
udelay() and select() seem to have the some problem...
Thank you for any suggestion.