A thread that sleeps in X milliseconds does not guarantee to sleep exactly that many milliseconds. I assume you have a statement that looks something like this:
while(1) {
...
sleep(10); // Sleep for 10 seconds.
// fetch timestamp and send
}
, (, 20 ) , . 10 , .
, , , .., (10) → → (10) , , (10) .
- (, C ):
bool expired = false;
double last, current;
double t1, t2;
double difference = 0;
while(1) {
...
last = (double)clock();
while(!expired) {
usleep(200);
current = (double)clock();
if(((current - last) / (double)CLOCKS_PER_SEC) >= (10.0 - difference))
expired = true;
}
t1 = (double)clock();
t2 = (double)clock();
difference = (t2 - t1) / (double)CLOCKS_PER_SEC;
expired = false;
}
C, , QueryPerformanceFrequency/QueryPerformanceCounter.
LONG_INTEGER freq;
LONG_INTEGER t2, t1;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&t1);
... Do something ....
QueryPerformanceCounter(&t2);
double duration = (double)(t2.QuadPart - t1.QuadPart) / (double)freq.QuadPart;