title: std::thread::join() hangs if called after main() exits when using VS2012 RC
body: <p>The following example runs successfully (i.e. doesn't hang) if compiled using Clang 3.2 or GCC 4.7 on Ubuntu 12.04, but hangs if I compile using VS11 Beta or VS2012 RC.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;thread&gt;
  #include "boost/thread/thread.hpp"
  
  void SleepFor(int ms) {
    std::this_thread::sleep_for(std::chrono::milliseconds(ms));
  }
  
  template&lt;typename T&gt;
  class ThreadTest {
   public:
    ThreadTest() : thread_([] { SleepFor(10); }) {}
    ~ThreadTest() {
      std::cout &lt;&lt; "About to join\t" &lt;&lt; id() &lt;&lt; '\n';
      thread_.join();
      std::cout &lt;&lt; "Joined\t\t" &lt;&lt; id() &lt;&lt; '\n';
    }
   private:
    std::string id() const { return typeid(decltype(thread_)).name(); }
    T thread_;
  };
  
  int main() {
    static ThreadTest&lt;std::thread&gt; std_test;
    static ThreadTest&lt;boost::thread&gt; boost_test;
  //  SleepFor(100);
  }
  </code></pre>
  
  <p>The issue appears to be that <code>std::thread::join()</code> never returns if it is invoked after <code>main</code> has exited.  It is blocked at <code>WaitForSingleObject</code> in <code>_Thrd_join</code> defined in cthread.c.</p>
  
  <p>Uncommenting <code>SleepFor(100);</code> at the end of <code>main</code> allows the program to exit properly, as does making <code>std_test</code> non-static.  Using <code>boost::thread</code> also avoids the issue.</p>
  
  <p>So I'd like to know if I'm invoking undefined behaviour here (seems unlikely to me), or if I should be filing a bug against VS2012?</p>