title: MsgWaitForMultipleObjectsEx deadlocks the main STA thread in MFC application
body: <p>What is the best was to do STA thread synchronization? </p>
  
  <p>I have a dialog based MFC application with two STA threads: the main and the second. I created the COM object in the main UI thread.</p>
  
  <p>I call the COM interface from the second thread. In the main thread, to make sure the second thread finishes before the main thread proceeds, I use a loop to wait for the thread. This loop calls MsgWaitForMultipleObjectsEx(timout=500) looply.</p>
  
  <p>I immediately got deadlocked on the wait. Then I realized that the MFC message pump, AfxInternalPumpMessage(), only helps with blocking calls but doesn't help at all with deadlock situations.</p>
  
  <p>Then I added Peek/Translate/DispatchMessage code into the wait loop and then all worked. </p>
  
  <p>Now, it seems that without hand coding the Peek/Translate/DispatchMessage loop, you can't do STA threads synchronization at all? Any wait call will deadlock you. Then what's the best or standard way to synchronize STA threads?</p>
  
  <p>Thanks!</p>