Advertisement
nex036ara

vektor<thread::id>

Mar 29th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <thread>
  4. using namespace std;
  5.  
  6. void f(thread::id &t_id){
  7.     t_id=this_thread::get_id();
  8. }
  9.  
  10. int main()
  11. {
  12.     int n;
  13.     cout<<"Unesi n: "<<endl;
  14.     cin>>n;
  15.  
  16.     vector<thread::id> a(n);
  17.     thread t[n];
  18.  
  19.     for(int i=0; i<n; ++i){
  20.        t[i]=thread(f,ref(a[i]));
  21.     }
  22.  
  23.     for(int i=0; i<n; ++i) {
  24.         t[i].join();
  25.     }
  26.  
  27.     for(int i=0; i<n; ++i)
  28.         cout<<a[i]<<endl;
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement