Skip to content

Instantly share code, notes, and snippets.

@z4yx
Created July 21, 2013 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z4yx/6048624 to your computer and use it in GitHub Desktop.
Save z4yx/6048624 to your computer and use it in GitHub Desktop.
sine graph in taskmgr
#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