C++基础-move进行线程的赋值

将一个线程移动到另外一个线程,其中的一个线程被销毁

//
// Created by Administrator on 2021/7/3.
//
#include<thread>
#include<iostream>
#include<cstdlib>

using namespace std;
//交换线程
int main()
{
    thread t1([](){
        int i = 0;
        while(1)
        {
            i++;
            if(i > 1000000000){
                break;
            }
        }
        cout << i << endl;
        system("pause");
    });


    //t1.join();
    thread t2 = move(t1); //线程移动, t2具备t1属性 t1挂了

    cout << t1.get_id() << endl;
    cout << t2.get_id() << endl;
    t2.join();
}
原文地址:https://www.cnblogs.com/my-love-is-python/p/14966261.html