CPU呈现正弦函数曲线

#include <stdlib.h>
#include <math.h>
#include <windows.h> 

    const double PI = 3.1415926;
	const int count = 200;
	const double w = 0.01;
	const int value = 300;
	
int main() {
	DWORD busySpan[count];  //DWORD是unsign long类型
	DWORD sleepSpan[count];
	int half = value / 2;
	double f = 0;
	for(int i = 0; i < 200; i++) {
		busySpan[i] = (DWORD)(half + sin(PI * f) * half);
		sleepSpan[i] = value - busySpan[i];
		f += w;
	}
	int j = 0;
	DWORD StartTime = 0;
	while(true) {
		DWORD StartTime = GetTickCount();
		int j = j % count;
		while((GetTickCount() - StartTime) <= busySpan[j])
	    ;
	    Sleep(sleepSpan[j])
	    ;
	    j++;
	}
	return 0;
	
}

 

posted @ 2016-03-03 10:12  梦幻之海  阅读(295)  评论(0编辑  收藏  举报