Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #define _WIN32_WINNT 0x0400
  2.  
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <string>
  6. #include <iostream>
  7. #include <thread>
  8. #include <time.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <mutex>
  12. #define _SECOND 2000000
  13. std::mutex bruh1;
  14. void bruh(int timeout)
  15. {
  16. srand(GetCurrentThreadId()^time(NULL));
  17. int timeSeconds = rand() % 10;
  18. HANDLE wTimer;
  19. __int64 endTime;
  20. LARGE_INTEGER quitTime;
  21. SYSTEMTIME now;
  22. wTimer = CreateWaitableTimer(NULL, FALSE, NULL);
  23. endTime = -5 * _SECOND*timeSeconds;
  24. quitTime.LowPart = (DWORD)(endTime & 0xFFFFFFFF);
  25. quitTime.HighPart = (LONG)(endTime >> 32);
  26. SetWaitableTimer(wTimer, &quitTime, 0, NULL, NULL, FALSE);
  27. GetSystemTime(&now);
  28. WaitForSingleObject(wTimer, _SECOND*-5*timeout);
  29. CloseHandle(wTimer);
  30. std::lock_guard<std::mutex> bruh2(bruh1);
  31. std::cout << "I died " << timeSeconds << " after"<<std::endl;
  32. }
  33. int main(int argc, char* argv[])
  34. {
  35. srand((unsigned int)time(NULL));
  36. int threads = 0;
  37. int timeout = 0;
  38. if (argc != 3)
  39. {
  40. std::cerr << "2 argument required";
  41. return 2;
  42. }
  43. else
  44. {
  45. threads = std::stoi(argv[1]);
  46. timeout = std::stoi(argv[2]);
  47. }
  48. for (size_t i = 0; i < threads; i++)
  49. {
  50. std::thread a(bruh,timeout);
  51. a.detach();
  52. }
  53. while (true)
  54. {
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement