首页 > 应用开发 > > c++ 多线程所有权转移?
#include<iostream>
#include<thread>
using namespace std;
//转移线程所有权
void fun1()
{
cout<<"this is fun1"<<endl;
};
void fun2()
{
cout<<"this is fun2 "<<endl;
};
int main()
{
thread t1(fun1);
thread t2=move(t1);
t1=thread(fun2);
//这个程序在这里就调用了terminate函数,但是明明这里t1没有所有权
//也就是说这里不用该调用terminate呀
//不明白
thread t3;
t3=move(t2);
t1=move(t3);//书上说这里才会因为T1本身有所有权而出现冲突
cout<<"main oooo"<<endl;
return 0;
}来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4479/viewspace-3141840/ ,如需转载,请注明出处,否则将追究法律责任。