1.

Solve : Why can't I sleep correct time using gettimeofday()??

Answer»

Below is a function from my coworker. It runs well at X86. I ran it at iMX6 and it didn't work because the program usually slept just HALF or twice the time as I expected. The INACCURACY is too large. How come?

inline VOID uusleep(INT usecs) {
struct timeval tpstart,tpend;

gettimeofday(&tpstart,NULL);
long ss = tpstart.tv_sec*1000000 + tpstart.tv_usec + usecs;

while(1) {
gettimeofday(&tpend,NULL);
if( (tpend.tv_sec*1000000 + tpend.tv_usec) >= ss) break;
}
}



Discussion

No Comment Found