Guest User

Untitled

a guest
Oct 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <thread>
  4.  
  5. using namespace std;
  6.  
  7. // The function we want to execute on the new thread.
  8. void task1(string msg)
  9. {
  10. cout << "task1 says: " << msg;
  11. }
  12.  
  13. int main()
  14. {
  15. // Constructs the new thread and runs it. Does not block execution.
  16. thread t1(task1, "Hello");
  17.  
  18. // Do other things...
  19.  
  20. // Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
  21. t1.join();
  22. }
  23.  
  24. g++ -o prog prog.cpp -std=c++11 -lpthread
Add Comment
Please, Sign In to add comment