Cam*_*ron 5 linux hyper-v clock virtual-machine
在遇到Erlang崩溃的一些问题之后,我编写了一个程序,它反复调用clock_gettime(CLOCK_MONOTONIC,&ts)并检查它是否会倒退,不幸的是它有时会倒退.
这是我正在使用的测试程序:
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
struct timespec ts_start;
struct timespec ts_end;
int i;
clock_gettime(CLOCK_MONOTONIC, &ts_start);
clock_gettime(CLOCK_MONOTONIC, &ts_end);
for(i = 0; i<10000000; i++) {
if(ts_end.tv_sec <= ts_start.tv_sec
&& ts_end.tv_nsec < ts_start.tv_nsec) {
printf("ERROR!\n");
return 1;
}
ts_start.tv_sec = ts_end.tv_sec;
ts_start.tv_nsec = ts_end.tv_nsec;
clock_gettime(CLOCK_MONOTONIC, &ts_end);
}
printf("OK\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我的Hyper-V VM(内核2.6.18-238.12.1.e15,已尝试其他)上,它偶尔会输出ERROR,但在物理机器上它总是输出OK.
知道为什么CLOCK_MONOTONIC不会单调吗?
| 归档时间: |
|
| 查看次数: |
745 次 |
| 最近记录: |