Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <Windows.h>
  6. #include <stdlib.h>
  7. #include <conio.h>
  8.  
  9. long int zmzwykla = 0;
  10. volatile int zmulotna = 0;
  11. long int zmatom = 0;
  12.  
  13. unsigned long __stdcall incrementDecrement (LPVOID v);
  14.  
  15. int main(int argc, char* argv[])
  16. {
  17.     HANDLE hw1;
  18.     hw1 = CreateThread(0, 0, incrementDecrement, 0, 0, 0);
  19.     HANDLE hw2;
  20.     hw2 = CreateThread(0, 0, incrementDecrement, 0, 0, 0);
  21.     HANDLE hw3;
  22.     hw3 = CreateThread(0, 0, incrementDecrement, 0, 0, 0);
  23.     while(1)
  24.     {
  25.         printf("%ld\t%ld\t%ld\n", zmzwykla, zmulotna, zmatom);
  26.         Sleep(300);
  27.     }
  28.     return 0;
  29. }
  30.  
  31. unsigned long __stdcall incrementDecrement (LPVOID v)
  32. {
  33.     while(1)
  34.     {
  35.     zmzwykla += 2;
  36.     zmzwykla--;
  37.     zmzwykla--;
  38.     zmulotna += 2;
  39.     zmulotna--;
  40.     zmulotna--;
  41.     InterlockedExchangeAdd(&zmatom, 2);
  42.     InterlockedDecrement(&zmatom);
  43.     InterlockedDecrement(&zmatom);
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement