Advertisement
Momir

Multithreading sa čekanjem

Feb 26th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <thread>
  4. using namespace std;
  5.  
  6. int foo()
  7. {
  8.     for (int i = 0; i < 5; i++) {
  9.         cout << "Thread " << i << endl;  
  10.         Sleep(500);
  11.     }
  12.  
  13.     return 0;
  14. }
  15.  
  16. int foo2()
  17. {
  18.     for (int i = 0; i < 5; i++) {
  19.         cout << "Thread2 " << i << endl;  
  20.         Sleep(500);
  21.     }
  22.  
  23.     return 0;
  24. }
  25.                
  26. int main()
  27. {
  28.     cout << "Pocetak" << endl;
  29.     Sleep(500);
  30.  
  31.     thread th1(foo);
  32.     thread th2(foo2);
  33.     th1.join();
  34.     th2.join();
  35.  
  36.     int i = 0;     
  37.     while (i++ < 10) {
  38.         cout << "Kraj " << i << endl;
  39.         Sleep(500);
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement