Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: C++ | Size: 0.67 KB | Hits: 107 | Expires: Never
This paste has a previous version, view the difference. 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.  
  19.         while(1)
  20.         {
  21.                 if(_kbhit()) {
  22.                         char ch = _getch();
  23.                         if(ch == 26)
  24.                         {
  25.                                 printf("Bye Bye\n");
  26.                                 exit(1);
  27.                         }
  28.                 }
  29.         }
  30.  
  31.         return 0;
  32. }
  33.  
  34.  
  35. int main()
  36. {
  37.         HANDLE hThreadArray[2];
  38.  
  39.         hThreadArray[0]=CreateThread(NULL,0,ThreadFunction1,NULL,0,NULL);
  40.         hThreadArray[1]=CreateThread(NULL,0,ThreadFunction2,NULL,0,NULL);
  41.  
  42.         WaitForMultipleObjects(2, hThreadArray, TRUE, INFINITE);
  43.  
  44.         return 1;
  45. }