Windows select 计时误差
测试:普通线程优先级
-
测试代码
// // [from] uthash/tests/keystat.c // void gettimeofday(struct timeval* p, void* tz /* IGNORED */) { LARGE_INTEGER q; static long long freq; static long long cyg_timer; QueryPerformanceFrequency(&q); freq = q.QuadPart; QueryPerformanceCounter(&q); cyg_timer = q.QuadPart; p->tv_sec = (long)(cyg_timer / freq); p->tv_usec = (long)(((cyg_timer % freq) * 1000000) / freq); }
double deviation_sum = 0.0; double deviation_cnt = 0.0; double deviation_max = 0.0; struct timeval lastSent; struct timeval lastPrint; gettimeofday(&lastSent, NULL); while(1) { FD_SET readfd; struct timeval timeout; //... timeout.tv_sec = interval / 1000000; timeout.tv_usec = interval % 1000000; gettimeofday(&lastSent, NULL); int reVal = select(num + 1, &readfd, NULL, NULL, &timeout