Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: None | Size: 0.64 KB | Hits: 44 | Expires: Never
Copy text to clipboard
  1. #include <conio.h>
  2. #include <ctype.h>
  3. #include <stdio.h>
  4. #include <Windows.h>
  5.  
  6. DWORD WINAPI ThreadFunction1(LPVOID lpParam)
  7. {
  8.         while(1)
  9.         {
  10.                 printf("Hello World Thread1!\n");
  11.                 Sleep(1000);
  12.         }
  13.         return 0;
  14. }
  15.  
  16. DWORD WINAPI ThreadFunction2(LPVOID lpParam)
  17. {
  18.         if(_kbhit()) {
  19.                 char ch = _getch();
  20.                 if(ch == 26)
  21.                 {
  22.                         printf("Bye Bye\n");
  23.                         exit(1);
  24.                 }
  25.         }
  26.  
  27.         return 0;
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33.         HANDLE hThreadArray[2];
  34.  
  35.         hThreadArray[0]=CreateThread(NULL,0,ThreadFunction1,NULL,0,NULL);
  36.         hThreadArray[1]=CreateThread(NULL,0,ThreadFunction2,NULL,0,NULL);
  37.  
  38.         WaitForMultipleObjects(2, hThreadArray, TRUE, INFINITE);
  39.  
  40.         return 1;
  41. }