首页 新闻 会员 周边

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

0
悬赏园豆:10 [已解决问题] 解决于 2017-04-02 19:44

#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;
}

邗影的主页 邗影 | 初学一级 | 园豆:73
提问于:2017-04-02 19:41
< >
分享
最佳答案
0

没有join函数......................

邗影 | 初学一级 |园豆:73 | 2017-04-02 19:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册