title: How to stop std thread safely?
body: <p>I'm developing a chat server and I have a question.</p>
  
  <p>How to stop <code>std::thread</code> safely?</p>
  
  <p>it is very easy problem, like this.</p>
  
  <pre><code>thread t(&amp;func);
  t.join();
  </code></pre>
  
  <p>but, if func is has infinite loop, join is not working.</p>
  
  <p>this is my source.</p>
  
  <pre><code>void CServerSocket::AcceptRun(boost::asio::io_service &amp;iosrv)
  {
      while (true)
      {
          auto sock = std::make_shared&lt;boost::asio::ip::tcp::socket&gt;(iosrv);
          m_Acceptor-&gt;accept(*sock);
  
          m_SocketList.push_back(std::make_shared&lt;CConnectionSocket&gt;(this, sock));
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>CServerSocket::~CServerSocket()
  {
      CLogManager::WriteLog("Stopping Server...");
      m_Acceptor-&gt;close();
      m_Acceptor.reset();
  
      // m_AcceptThread.detach(); This is right?
  
      CLogManager::WriteLog("Server Stoped!");
  }
  </code></pre>
  
  <p>I'm very wondering.
  Please help me.
  thank you.</p>