Advertisement
Guest User

threadcxx11.cxx

a guest
Mar 22nd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <ctime>
  3. #include <iostream>
  4. #include <thread>
  5. #include <unistd.h>
  6.  
  7. using namespace std;
  8.  
  9. void threadfunc(int x)
  10. {
  11.     usleep(rand() % 100000);
  12.     cout << "Hello, C++11 (id: " << x << ")" << endl;
  13. }
  14.  
  15. int main()
  16. {
  17.     srand(time(0));
  18.  
  19.     thread t1(&threadfunc, 1);
  20.     thread t2(&threadfunc, 2);
  21.  
  22.     t1.join();
  23.     t2.join();
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement