Created
November 23, 2014 22:03
-
-
Save leonelsr/66ce5a68974bffabb81c to your computer and use it in GitHub Desktop.
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
/* Use 100% CPU on multithreaded Windows systems */ | |
#include <Windows.h> | |
#include <stdio.h> | |
#define NUM_THREADS 4 | |
DWORD WINAPI mythread(__in LPVOID lpParameter) | |
{ | |
printf("Thread inside %d \n", GetCurrentThreadId()); | |
volatile unsigned x = 0, y = 1; | |
while (x++ || y++); | |
return 0; | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
HANDLE handles[NUM_THREADS]; | |
DWORD mythreadid[NUM_THREADS]; | |
int i; | |
for (i = 0; i < NUM_THREADS; i++) | |
{ | |
handles[i] = CreateThread(0, 0, mythread, 0, 0, &mythreadid[i]); | |
printf("Thread after %d \n", mythreadid[i]); | |
} | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment