Guest User

Untitled

a guest
Dec 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <thread>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. //g++ tutorial2.cpp -std=c++0x -lpthread                                                        
  8.  
  9. int main()
  10. {
  11.   vector<thread> workers;
  12.   for( int i = 0; i < 10; ++i )
  13.     {
  14.       workers.push_back(thread([i]()
  15.                                {
  16.                                  printf("Hi from thread %i\n",i);
  17.                                  //cout << "Hi from thread " << i << endl;                      
  18.                                }));
  19.     }
  20.  
  21.   cout << "Hi from main!\n";
  22.   for_each(workers.begin(), workers.end(), [](thread &th)
  23.            {
  24.              th.join();
  25.            });
  26. return 0;
  27. }
Add Comment
Please, Sign In to add comment