Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- long z1=0;
- int z2=0;
- volatile long z3=0;
- DWORD WINAPI watek1(void *v)
- {
- int i;
- while(1)
- {
- z1=z1+3;
- z1--;
- z1--;
- z1--;
- z2=z2+3;
- z2--;
- z2--;
- z2--;
- InterlockedExchangeAdd(&z3,3);
- InterlockedDecrement(&z3);
- InterlockedDecrement(&z3);
- InterlockedDecrement(&z3);
- }
- }
- DWORD WINAPI watek2(void *v)
- {
- while(1)
- {
- z1=z1+3;
- z1--;
- z1--;
- z1--;
- z2=z2+3;
- z2--;
- z2--;
- z2--;
- InterlockedExchangeAdd(&z3,3);
- InterlockedDecrement(&z3);
- InterlockedDecrement(&z3);
- InterlockedDecrement(&z3);
- }
- }
- int main(int argc, char *argv[])
- {
- int i;
- //DWORD IdWatku1, IdWatku2, IdWatku3;
- HANDLE watek_a, watek_b;
- watek_a = CreateThread(NULL, 0, watek1, 0, 0, 0);
- //SetThreadPriority(watek_a,0);
- watek_b=CreateThread(NULL, 0, watek2, 0, 0,0);
- //SetThreadPriority(watek_b,-1);
- //watek_c=CreateThread(NULL, 0, watek3, 0,0,0);
- //SetThreadPriority(watek_c,-2);
- for(i=1;i<1000;i++)
- {
- Sleep(1000);
- printf("z1= %d \t z2=%d \t z3=%d \n",z1,z2,z3);
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment