#include"iostream"#include"thread"#include<utility>#include<chrono>#include<functional>#include<atomic>usingnamespace std;voidtask(){
cout <<"thread"<<endl;}voidf1(int n){for(int i =0; i <5; i++){
cout <<"f1 thread "<< n <<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(10));}}voidf2(int& n){for(int i =0; i <5; i++){
cout <<"f2 thread executing "<< endl ;++n;
std::this_thread::sleep_for(std::chrono::milliseconds(10));}}intmain(){int n =0;
thread t1;
thread t2(f1, n+1);
thread t3(f2, std::ref(n));
thread t4(std::move(t3));// t4 is now running f2(). t3 is no longer a thread
t2.join();
t4.join();
cout <<"final value of n is "<< n << endl;getchar();return0;}