title: Do threads clean-up after themselves in Win32/MFC and POSIX?
body: <p>I am working on a multithreaded program using C++ and Boost. I am using a helper thread to eagerly initialize a resource asynchronously. If I detach the thread and all references to the thread go out of scope, have I leaked any resources? Or does the thread clean-up after itself (i.e. it's stack and any other system resources needed for the itself)?</p>
  
  <p>From what I can see in the docs (and what I recall from pthreads 8 years ago), there's not explicit "destory thread" call that needs to be made.</p>
  
  <p>I would like the thread to execute asynchronously and when it comes time to use the resource, I will check if an error has occured. The rough bit of code would look something like:</p>
  
  <pre><code>//Assume this won't get called frequently enough that next_resource won't get promoted
  //before the thread finishes.
  PromoteResource() {
     current_resource_ptr = next_resource_ptr;
     next_resource_ptr.reset(new Resource());
     callable = bind(Resource::Initialize, next_resource); //not correct syntax, but I hope it's clear
     boost::thread t(callable);
     t.start();
  }
  </code></pre>
  
  <p>Of course--I understand that normal memory-handling problems still exist (forget to delete, bad exception handling, etc)... I just need confirmation that the thread itself isn't a "leak".</p>
  
  <p>Edit: A point of clarification, I want to make sure this isn't technically a leak:</p>
  
  <pre><code>void Run() {
     sleep(10 seconds);
  }
  
  void DoSomething(...) {
     thread t(Run);
     t.run();
  } //thread detaches, will clean itself up--the thread itself isn't a 'leak'?
  </code></pre>
  
  <p>I'm fairly certain everything is cleaned up after 10 seconds-ish, but I want to be absolutely certain.</p>