title: Wait for AfxBeginThread/CWinThread message pump to be active?
body: <p>I'm calling AfxBeginThread and using CWinThread to spin up a UI thread in my MFC app.</p>
  
  <p>I've noticed that if my main thread tries to PostThreadMessage() to my new thread before the CWinThread::InitInstance() function returns, then PostThreadMessage() will return the error: invalid thread handle.</p>
  
  <p>My guess is that the message pump on the new thread isn't setup until after InitInstance returns.  The example code I've seen for AfxBeginThread and the documentation I've read don't do a good job of explaining this behavior, or show a pattern to wait for the thread to be initialized.</p>
  
  <p>What's the best way of blocking my main thread until InitInstance has returned and the thread's message pump is ready to receive messages?</p>