timus221

Untitled

Mar 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. long z1=0;
  5. int z2=0;
  6. volatile long z3=0;
  7.  
  8. DWORD WINAPI watek1(void *v)
  9. {
  10. int i;
  11. while(1)
  12. {
  13. z1=z1+3;
  14. z1--;
  15. z1--;
  16. z1--;
  17.  
  18.  
  19. z2=z2+3;
  20. z2--;
  21. z2--;
  22. z2--;
  23.  
  24. InterlockedExchangeAdd(&z3,3);
  25. InterlockedDecrement(&z3);
  26. InterlockedDecrement(&z3);
  27. InterlockedDecrement(&z3);
  28.  
  29. }
  30.  
  31. }
  32.  
  33.  
  34.  
  35.  
  36. DWORD WINAPI watek2(void *v)
  37. {
  38.  
  39. while(1)
  40. {
  41. z1=z1+3;
  42. z1--;
  43. z1--;
  44. z1--;
  45.  
  46.  
  47. z2=z2+3;
  48. z2--;
  49. z2--;
  50. z2--;
  51.  
  52. InterlockedExchangeAdd(&z3,3);
  53. InterlockedDecrement(&z3);
  54. InterlockedDecrement(&z3);
  55. InterlockedDecrement(&z3);
  56. }
  57.  
  58. }
  59.  
  60.  
  61.  
  62. int main(int argc, char *argv[])
  63. {
  64.  
  65. int i;
  66. //DWORD IdWatku1, IdWatku2, IdWatku3;
  67. HANDLE watek_a, watek_b;
  68.  
  69.  
  70. watek_a = CreateThread(NULL, 0, watek1, 0, 0, 0);
  71. //SetThreadPriority(watek_a,0);
  72.  
  73. watek_b=CreateThread(NULL, 0, watek2, 0, 0,0);
  74. //SetThreadPriority(watek_b,-1);
  75. //watek_c=CreateThread(NULL, 0, watek3, 0,0,0);
  76. //SetThreadPriority(watek_c,-2);
  77.  
  78. for(i=1;i<1000;i++)
  79. {
  80. Sleep(1000);
  81. printf("z1= %d \t z2=%d \t z3=%d \n",z1,z2,z3);
  82.  
  83. }
  84.  
  85.  
  86. system("PAUSE");
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment