使用swap进行两个线程的交换 

#include<thread>
#include<iostream>

using namespace std;
//交换线程
int main1()
{
    thread t1([](){cout << "fangfang"<<endl;});
    thread t2([](){cout << "huahua"<<endl;});
    cout << "t1.get_id()" << t1.get_id() << "t2.get_id()" << t2.get_id() << endl;
    swap(t1, t2);
    cout << "t1.get_id()" << t1.get_id() << "t2.get_id()" << t2.get_id() << endl;
    t1.join();
    t2.join();
}

 

posted on 2021-07-03 14:03  python我的最爱  阅读(191)  评论(0编辑  收藏  举报