VMware QueryPerformanceCounter/GetTickCount 悬案
生活随笔
收集整理的這篇文章主要介紹了
VMware QueryPerformanceCounter/GetTickCount 悬案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近發現在VMware的客戶機上,兩次 QueryPerformanceCounter 相差的數值會特別大。還不知道如何解決。。
測試程序如下
#include <windows.h>DWORD WINAPI TestThread(PVOID x) {DWORD i = 0;LARGE_INTEGER t0, t1, freq;ULONG u0, u1;ULONG tick0, tick1;QueryPerformanceFrequency(&freq);while(1){tick0 = GetTickCount();QueryPerformanceCounter(&t0);Sleep(20);tick1 = GetTickCount();QueryPerformanceCounter(&t1);u0 = (ULONG)(t0.QuadPart * 1000 / freq.QuadPart);u1 = (ULONG)(t1.QuadPart * 1000 / freq.QuadPart);if(u1 - u0 > 1000){printf("tick0:%u u0:%u t0:%lld\n", tick0, u0, t0.QuadPart);printf("tick1:%u u1:%u t1:%lld\n", tick1, u1, t1.QuadPart);break;}}return 0; }int main(int argc, char *argv[]) {DWORD t;CreateThread(NULL, 0, TestThread, 0, 0, &t);while(1){Sleep(1000);}return 0; }運行一段時間,就會有詭異的結果,如下
tick0:256061203 u0:484451150 t0:1896171838229 tick1:263509156 u1:499347347 t1:1954476477852 tick0:86261453 u0:86261495 t0:862614951505 tick1:93717562 u1:93717612 t1:937176121575為什么Sleep(20)前后的tick相差巨大呢?
?
測試環境是 ESXi 6.7?
客戶機1 Win10 1703
客戶機2 Win10 1803
?
總結
以上是生活随笔為你收集整理的VMware QueryPerformanceCounter/GetTickCount 悬案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 重写了GD32VF103的启动脚本和链接
- 下一篇: 苹果的组件保护机制 AuthCP