Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <thread>
- using namespace std;
- // The function we want to execute on the new thread.
- void task1(string msg)
- {
- cout << "task1 says: " << msg;
- }
- int main()
- {
- // Constructs the new thread and runs it. Does not block execution.
- thread t1(task1, "Hello");
- // Do other things...
- // Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
- t1.join();
- }
- g++ -o prog prog.cpp -std=c++11 -lpthread
Add Comment
Please, Sign In to add comment