title: When should I use std::thread::detach?
body: <p>Sometime I have to use <code>std::thread</code> to speed up my application. I also know <code>join()</code> waits until a thread completes. This is easy to understand, but what's the difference between calling <code>detach()</code> and not calling it?</p>
  
  <p>I thought that without <code>detach()</code>, the thread's method will work using a thread independently.</p>
  
  <p>Not detaching:</p>
  
  <pre><code>void Someclass::Somefunction() {
      //...
  
      std::thread t([ ] {
          printf("thread called without detach");
      });
  
      //some code here
  }
  </code></pre>
  
  <p>Calling with detaching:</p>
  
  <pre><code>void Someclass::Somefunction() {
      //...
  
      std::thread t([ ] {
          printf("thread called with detach");
      });
  
      t.detach();
  
      //some code here
  }
  </code></pre>