Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include "windows.h"
  2. #include <iostream>
  3.  
  4.  
  5. DWORD WINAPI ThreadFn(LPVOID vpParam);
  6.  
  7. int main() {
  8.     using namespace std;
  9.  
  10.     // Create the thread and pass in the function pointer and counter
  11.     unsigned int uiCounter = 0;
  12.     DWORD qThreadID;
  13.     HANDLE hThread = CreateThread(0, 0, ThreadFn, &uiCounter, 0, &qThreadID);
  14.  
  15.     // Loop until the user enters 'q'
  16.     char cChar = ' ';
  17.     while (cChar != 'q') {
  18.         cout << uiCounter << endl;
  19.         cChar = (char)getchar();
  20.     }
  21.  
  22.     // Close the handle to the thread
  23.     CloseHandle(hThread);
  24.  
  25.     return 0;
  26. }
  27.  
  28.  
  29. DWORD WINAPI ThreadFn(LPVOID vpParam)
  30. {
  31.     unsigned int& uirCounter = *((unsigned int*)vpParam);
  32.     // Increment up to the maximum value
  33.     while (uirCounter < 100000) {
  34.         ++uirCounter;
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement