Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <Windows.h>
- #include <stdio.h>
- using namespace std;
- long int* X = NULL;
- long int* Y = NULL;
- long int* Z = NULL;
- void watekX()
- {
- while (true)
- {
- (*X)++;
- }
- }
- void watekY()
- {
- while (true)
- {
- (*Y)++;
- }
- }
- void watekZ()
- {
- while (true)
- {
- (*Z)++;
- }
- }
- int main()
- {
- DWORD id[3];
- calloc(3, sizeof(long int*));
- HANDLE hnX, hnY, hnZ;
- hnX = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)watekX, 0, 0, &id[0]);
- hnY = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)watekY, 0, 0, &id[1]);
- hnZ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)watekZ, 0, 0, &id[2]);
- SetThreadPriority(hnX, 2);
- SetThreadPriority(hnY, 3);
- SetThreadPriority(hnZ, 2);
- while (true)
- {
- //Podstawy 0.
- watekX();
- watekY();
- watekZ();
- //Zadanie 1.
- ResumeThread(hnX);
- ResumeThread(hnY);
- SuspendThread(hnY);
- ResumeThread(hnZ);
- Sleep(1000);
- printf("X = %d | Y = %d | Z = %d\n", X, Y, Z);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment