小编tob*_*bin的帖子

如何终止std :: thread?

我目前正在开发一个程序,需要从套接字服务器下载一些图像,下载工作将执行很长时间.所以,我创造了一个新std::thread的做法.

一旦下载,std::thread它将调用当前Class的成员函数,但此类可能已被释放.所以,我有一个例外.

如何解决这个问题呢?

void xxx::fun1()
{
   ...
}
void xxx::downloadImg()
{
 ...a long time
  if(downloadComplete)
  {
   this->fun1();
  }
}
void xxx::mainProcees()
{
  std::thread* th = new thread(mem_fn(&xxx::downloadImg),this);
  th->detach();
  //if I use th->join(),the UI will be obstructed
}
Run Code Online (Sandbox Code Playgroud)

c++ multithreading cocos2d-x c++11 stdthread

5
推荐指数
1
解决办法
7479
查看次数

标签 统计

c++ ×1

c++11 ×1

cocos2d-x ×1

multithreading ×1

stdthread ×1