title: Linux C++: Does a return from main() cause a multithreaded app to terminate?
body: <p>This question seems like it's probably a duplicate, but I was unable to find one. If I missed a previous question, apologies.</p>
  
  <p>In Java, where I have most of my experience, if your main() forks a thread and immediately returns the process continues to run until all (non-daemon) threads in the process have stopped.</p>
  
  <p>In C++, this appears not to be the case - as soon as the main thread returns the process is terminating with other threads still running. For my current app this is easily solved with the application of <code>pthread_join()</code> but I'm wondering what causes this behavior. Is this compiler (gcc) specific, pthreads specific, or is kind of behavior shared across most/all platforms for which C++ has been implemented? Is this behavior configurable within pthreads (I've looked through the pthread api at the <code>pthread_attr_*()</code> functions and didn't see anything that looked relevant.)?</p>
  
  <p>Completely separate question, but while you're here ... what would one use <code>pthread_detatch()</code> for?</p>