Guest User

Untitled

a guest
Sep 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. DWORD WINAPI increment(CONST LPVOID lpParam)
  2. {
  3. CONST HANDLE hMutex = (CONST HANDLE)lpParam;
  4. while (testMutex < testMax)
  5. {
  6. WaitForSingleObject(hMutex, INFINITE);
  7. testMutex++;
  8. if(testMutex<testMax)
  9. std::cout << testMutex << std::endl;
  10. ReleaseMutex(hMutex);
  11. }
  12. ExitThread(0);
  13. }
  14.  
  15. void createMutexAndThread()
  16. {
  17. HANDLE hMutex = CreateMutex(NULL, FALSE, NULL);
  18. HANDLE hThreads[500];
  19. for (int i = 0; i < 500; i++)
  20. {
  21. hThreads[i] = CreateThread(NULL, 0, &increment, hMutex, 0, NULL);
  22. }
  23. WaitForSingleObject(hThreads[0], INFINITE);
  24. //WaitForMultipleObjects(64, hThreads, TRUE, INFINITE);
  25.  
  26. std::cout << "1n";
  27. for (int i = 0; i < 500; i++) {
  28. CloseHandle(hThreads[i]);
  29. }
  30.  
  31. }
Add Comment
Please, Sign In to add comment