Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include <stdlib.h>
- #include <conio.h>
- long int zmzwykla = 0;
- volatile int zmulotna = 0;
- long int zmatom = 0;
- unsigned long __stdcall incrementDecrement (LPVOID v);
- int main(int argc, char* argv[])
- {
- HANDLE hw1;
- hw1 = CreateThread(0, 0, incrementDecrement, 0, 0, 0);
- HANDLE hw2;
- hw2 = CreateThread(0, 0, incrementDecrement, 0, 0, 0);
- HANDLE hw3;
- hw3 = CreateThread(0, 0, incrementDecrement, 0, 0, 0);
- while(1)
- {
- printf("%ld\t%ld\t%ld\n", zmzwykla, zmulotna, zmatom);
- Sleep(300);
- }
- return 0;
- }
- unsigned long __stdcall incrementDecrement (LPVOID v)
- {
- while(1)
- {
- zmzwykla += 2;
- zmzwykla--;
- zmzwykla--;
- zmulotna += 2;
- zmulotna--;
- zmulotna--;
- InterlockedExchangeAdd(&zmatom, 2);
- InterlockedDecrement(&zmatom);
- InterlockedDecrement(&zmatom);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement