-
-
Save z4yx/6048624 to your computer and use it in GitHub Desktop.
sine graph in taskmgr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <math.h> | |
const int COUNT = 200, INTERVAL = 300; | |
const double SPLIT = 0.01; | |
int busySpan[COUNT], idleSpan[COUNT]; | |
void Draw() | |
{ | |
DWORD startTime = 0; | |
int j = 0; | |
while (true) | |
{ | |
j = j % COUNT; | |
startTime = GetTickCount(); | |
while (GetTickCount() - startTime <= busySpan[j]) | |
; | |
Sleep(idleSpan[j]); | |
j++; | |
} | |
} | |
int main() | |
{ | |
HANDLE hThread[32]; | |
SYSTEM_INFO si; | |
int i; | |
double radian = 0; | |
for (i = 0; i < COUNT; i++) | |
{ | |
busySpan[i] = (DWORD) (sin(M_PI * radian) * INTERVAL); | |
idleSpan[i] = INTERVAL - busySpan[i]; | |
radian += SPLIT; | |
} | |
ZeroMemory(&si, sizeof(si)); | |
GetSystemInfo(&si); | |
for (int i = 0; i < si.dwNumberOfProcessors; i++) | |
{ | |
hThread[i] = NULL; | |
hThread[i] = CreateThread(NULL, NULL, &Draw, NULL, CREATE_SUSPENDED, NULL); | |
SetThreadAffinityMask(hThread[i], (1<<i) ); | |
ResumeThread(hThread[i]); | |
} | |
WaitForMultipleObjects(si.dwNumberOfProcessors, hThread, true, INFINITE); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment