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;
	
}
原文地址:https://www.cnblogs.com/xiaohaigege/p/5237500.html