Untitled
By: a guest | Mar 20th, 2010 | Syntax:
C++ | Size: 0.67 KB | Hits: 107 | Expires: Never
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <Windows.h>
DWORD WINAPI ThreadFunction1(LPVOID lpParam)
{
while(1)
{
printf("Hello World Thread1!\n");
Sleep(1000);
}
return 0;
}
DWORD WINAPI ThreadFunction2(LPVOID lpParam)
{
while(1)
{
if(_kbhit()) {
char ch = _getch();
if(ch == 26)
{
printf("Bye Bye\n");
exit(1);
}
}
}
return 0;
}
int main()
{
HANDLE hThreadArray[2];
hThreadArray[0]=CreateThread(NULL,0,ThreadFunction1,NULL,0,NULL);
hThreadArray[1]=CreateThread(NULL,0,ThreadFunction2,NULL,0,NULL);
WaitForMultipleObjects(2, hThreadArray, TRUE, INFINITE);
return 1;
}