Guest User

Untitled

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