Advertisement
Pagoniusz

Untitled

Apr 9th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <stdio.h>
  3. #include <utility>
  4. #include <conio.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8.  
  9. DWORD WINAPI silnia(LPVOID lpParam)
  10. {
  11.     int i = 1;
  12.     int silnia = 1;
  13.     Sleep(500);
  14.     while (silnia < 100000)
  15.     {
  16.         silnia *= i;
  17.         i++;
  18.     }
  19.     cout << "Wynik silni: " << silnia << endl;
  20.     return 0;
  21.  
  22. }
  23. DWORD WINAPI fibb(LPVOID lpParam)
  24. {
  25.     int  fib1 = 0, fib2 = 1;
  26.     int fib3 = 0;
  27.  
  28.     Sleep(1500);
  29.     while (fib3 < 100000)
  30.     {
  31.         fib3 = fib1 + fib2;
  32.  
  33.         fib1 = fib2;
  34.         fib2 = fib3;
  35.     }
  36.     cout << "Wynik fibb: " << fib3 << endl;
  37.  
  38.     return 0;
  39. }
  40. DWORD WINAPI potega(LPVOID lpParam)
  41. {
  42.     int i = 1;
  43.     int p2 = 1;
  44.     Sleep(1000);
  45.     while (p2 < 100000)
  46.     {
  47.         p2 *= 2;
  48.     }
  49.     cout << "Wynik potegi: " << p2 << endl;
  50.  
  51.     return 0;
  52. }
  53.  
  54. HANDLE threads[3];
  55.  
  56. int main(int argc, char **argv)
  57. {
  58.     threads[0] = CreateThread(NULL, 0, silnia, NULL, 0, NULL);
  59.     if (threads[0] == NULL)
  60.         ExitProcess(1);
  61.     else
  62.         cout << "Proces silnia utworzony \n";
  63.  
  64.     threads[1] = CreateThread(NULL, 0, fibb, NULL, 0, NULL);
  65.     if (threads[1] == NULL)
  66.         ExitProcess(1);
  67.     else
  68.         cout << "Proces fibb utworzony \n";
  69.  
  70.     threads[2] = CreateThread(NULL, 0, potega, NULL, 0, NULL);
  71.     if (threads[2] == NULL)
  72.         ExitProcess(1);
  73.     else
  74.         cout << "Proces potega utworzony \n";
  75.    
  76.  
  77.  
  78.     DWORD wfmo = WaitForMultipleObjects(3, threads, TRUE, INFINITE);
  79.  
  80.     cout << "Wykonano wszystkie procesy \n";
  81.     CloseHandle(threads[0]);
  82.     CloseHandle(threads[1]);
  83.     CloseHandle(threads[2]);
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement