title: Trouble understanding MSDN's documentation on _beginthreadex and _endthreadex
body: <p>I'm reading the <a href="http://msdn.microsoft.com/en-us/library/kdzttdcb%28VS.80%29.aspx" rel="nofollow noreferrer">documentation</a> about <code>_beginthreadex</code> and <code>_endthreadex</code> but there are a few things I don't understand.</p>
  
  <p>Note that the documentation keeps documenting the "extended" and normal functions at the same time, but I'm not using <code>_beginthread</code> and <code>_endthread</code>; only their extended versions.</p>
  
  <hr>
  
  <blockquote>
    <p>You can call _endthread or
    _endthreadex explicitly to terminate a thread; however, _endthread or
    _endthreadex is called automatically when the thread returns from the
    routine passed as a parameter.
    Terminating a thread with a call to
    endthread or _endthreadex helps to
    ensure proper recovery of resources
    allocated for the thread.</p>
  </blockquote>
  
  <ul>
  <li>If <code>_endthreadex</code> is called automatically, how come calling it helps to ensure "proper recovery of resources"? It shouldn't make any difference whether I call it or not, or does it?</li>
  </ul>
  
  <hr>
  
  <blockquote>
    <p>_endthread automatically closes the thread handle (whereas _endthreadex
    does not). Therefore, when using
    _beginthread and _endthread, do not explicitly close the thread handle by
    calling the Win32 CloseHandle API.</p>
  </blockquote>
  
  <ul>
  <li>If <code>_endthreadex</code> <strong>does not</strong> close the handle, how come I shouldn't close it with <code>CloseHandle</code>?</li>
  <li><p>All of my threads only voluntarily terminate by returning from their main function and are never forcefully terminated. According to the documentation, when this happens <code>_endthreadex</code> is called automatically.</p>
  
  <p>This though won't close the handle. Assuming that I do need to close it, notwithstanding with what is said above, how can I do that since at this point the thread is dead? Should I somehow close it from another thread? What happens if I leave it open?</p></li>
  </ul>