ITPub博客

首页 > 应用开发 > > c++ 多线程所有权转移?

c++ 多线程所有权转移?

作者:dav2100 时间:2019-08-20 10:42:14 0 删除 编辑
#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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-17

  • 博文量
    176
  • 访问量
    17570