Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <stdio.h>
- #include <utility>
- #include <conio.h>
- #include <iostream>
- using namespace std;
- DWORD WINAPI silnia(LPVOID lpParam)
- {
- int i = 1;
- int silnia = 1;
- Sleep(500);
- while (silnia < 100000)
- {
- silnia *= i;
- i++;
- }
- cout << "Wynik silni: " << silnia << endl;
- return 0;
- }
- DWORD WINAPI fibb(LPVOID lpParam)
- {
- int fib1 = 0, fib2 = 1;
- int fib3 = 0;
- Sleep(1500);
- while (fib3 < 100000)
- {
- fib3 = fib1 + fib2;
- fib1 = fib2;
- fib2 = fib3;
- }
- cout << "Wynik fibb: " << fib3 << endl;
- return 0;
- }
- DWORD WINAPI potega(LPVOID lpParam)
- {
- int i = 1;
- int p2 = 1;
- Sleep(1000);
- while (p2 < 100000)
- {
- p2 *= 2;
- }
- cout << "Wynik potegi: " << p2 << endl;
- return 0;
- }
- HANDLE threads[3];
- int main(int argc, char **argv)
- {
- threads[0] = CreateThread(NULL, 0, silnia, NULL, 0, NULL);
- if (threads[0] == NULL)
- ExitProcess(1);
- else
- cout << "Proces silnia utworzony \n";
- threads[1] = CreateThread(NULL, 0, fibb, NULL, 0, NULL);
- if (threads[1] == NULL)
- ExitProcess(1);
- else
- cout << "Proces fibb utworzony \n";
- threads[2] = CreateThread(NULL, 0, potega, NULL, 0, NULL);
- if (threads[2] == NULL)
- ExitProcess(1);
- else
- cout << "Proces potega utworzony \n";
- DWORD wfmo = WaitForMultipleObjects(3, threads, TRUE, INFINITE);
- cout << "Wykonano wszystkie procesy \n";
- CloseHandle(threads[0]);
- CloseHandle(threads[1]);
- CloseHandle(threads[2]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement