usleep takes to much time !
Von: , Frage gestellt am Mo, 28. Mai 2001
Hello all,
when I run the following programm
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
void my_usleep(unsigned int microseconds);
int main()
{
my_usleep(1e6);
my_usleep(1e5);
my_usleep(1e4);
my_usleep(1e3);
my_usleep(1e2);
my_usleep(1);
printf("Finished\n");
}
void my_usleep(unsigned int microseconds)
{
clock_t tick1=-1, tick2=-1;
double dClock = -1;
struct tms tStruct1, tStruct2;
if((tick1 = times(&tStruct1))== -1) printf("Error time 1\n");
usleep(microseconds);
if((tick2 = times(&tStruct2))== -1) printf("Error time 2\n");
if((dClock = sysconf(_SC_CLK_TCK)) < 0) printf("Error sysconf \n");
printf("usleep(%d) takes %6.2f ms\n", microseconds, (1000*(tick2 -
tick1)/dClock) );
return;
}
I get the following output:
usleep(1000000) takes 1010.00 ms usleep(100000) takes 110.00 ms usleep(10000) takes 20.00 ms usleep(1000) takes 20.00 ms usleep(100) takes 20.00 ms usleep(1) takes 20.00 ms Finished
Please, can anybody tell me why a usleep(1 usec) takes 20 ms ?
(Linux 2.4, glibc2.2, gcc 2.95.2)
Thanks
Lars
