timus221

Untitled

Mar 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 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. /*
  8. long int* X = NULL;
  9. long int* Y = NULL;
  10. long int* Z = NULL;
  11. */
  12. long int X=0;
  13. long int Y=0;
  14. long int Z=0;
  15.  
  16.  
  17. DWORD WINAPI watekX(void *v)
  18. {
  19. while (true)
  20. {
  21. X++;
  22. }
  23. }
  24. DWORD WINAPI watekY(void *v)
  25. {
  26. while (true)
  27. {
  28. Y++;
  29. }
  30. }
  31. DWORD WINAPI watekZ(void *v)
  32. {
  33. while (true)
  34. {
  35. Z++;
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. DWORD id0,id1,id2;
  42. //calloc(3, sizeof(long int*));
  43. HANDLE hnX, hnY, hnZ;
  44. hnX = CreateThread(NULL, 0, watekX, 0, 0, &id0);
  45. hnY = CreateThread(NULL, 0, watekY, 0, 0, &id1);
  46. hnZ = CreateThread(NULL, 0, watekZ, 0, 0, &id2);
  47.  
  48. SetThreadPriority(hnX, 2);
  49. SetThreadPriority(hnY, 3);
  50. SetThreadPriority(hnZ, 2);
  51.  
  52. while (true)
  53. {
  54. //Podstawy 0.
  55. //watekX();
  56. //watekY();
  57. //watekZ();
  58.  
  59. /* //Zadanie 1.
  60. ResumeThread(hnX);
  61. ResumeThread(hnY);
  62. SuspendThread(hnY);
  63. ResumeThread(hnZ);
  64. */
  65. Sleep(10);
  66. printf("X = %d | Y = %d | Z = %d\n", X, Y, Z);
  67. }
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment