title: How to terminate a std::thread?
body: <p>I am currently developing a program that needs to download some images from the socket server,and the downloading work will execute a long time. So, I create a new <code>std::thread</code> to do that. </p>
  
  <p>Once it's downloaded,the <code>std::thread</code> will call a member function of current Class, but this Class is likely to have been released. So, I got a exception.</p>
  
  <p>How to solve this problem?</p>
  
  <pre><code>void xxx::fun1()
  {
     ...
  }
  void xxx::downloadImg()
  {
   ...a long time
    if(downloadComplete)
    {
     this-&gt;fun1();
    }
  }
  void xxx::mainProcees()
  {
    std::thread* th = new thread(mem_fn(&amp;xxx::downloadImg),this);
    th-&gt;detach();
    //if I use th-&gt;join(),the UI will be obstructed
  }
  </code></pre>