timus221

Untitled

Mar 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <Windows.h>
  4. #include <stdio.h>
  5. using namespace std;
  6.  
  7. long int* X = NULL;
  8. long int* Y = NULL;
  9. long int* Z = NULL;
  10.  
  11. void watekX()
  12. {
  13. while (true)
  14. {
  15. (*X)++;
  16. }
  17. }
  18. void watekY()
  19. {
  20. while (true)
  21. {
  22. (*Y)++;
  23. }
  24. }
  25. void watekZ()
  26. {
  27. while (true)
  28. {
  29. (*Z)++;
  30. }
  31. }
  32.  
  33. int main()
  34. {
  35. DWORD id[3];
  36. calloc(3, sizeof(long int*));
  37. HANDLE hnX, hnY, hnZ;
  38. hnX = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)watekX, 0, 0, &id[0]);
  39. hnY = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)watekY, 0, 0, &id[1]);
  40. hnZ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)watekZ, 0, 0, &id[2]);
  41.  
  42. SetThreadPriority(hnX, 2);
  43. SetThreadPriority(hnY, 3);
  44. SetThreadPriority(hnZ, 2);
  45.  
  46. while (true)
  47. {
  48. //Podstawy 0.
  49. watekX();
  50. watekY();
  51. watekZ();
  52.  
  53. //Zadanie 1.
  54. ResumeThread(hnX);
  55. ResumeThread(hnY);
  56. SuspendThread(hnY);
  57. ResumeThread(hnZ);
  58.  
  59. Sleep(1000);
  60. printf("X = %d | Y = %d | Z = %d\n", X, Y, Z);
  61. }
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment