title: QT QEventLoop/QThread how to synchronize on an event loop?
body: <p>I need a way to know when an event loop has started and when it is about to exit. I am trying to synchronize between threads and there is hard to resolve race condition involving <code>isRunning</code> at the times when the loop starts and when it exits.</p>
  
  <p>I believe for starting I can simply post an event since it will be queued and dispatched once it starts. But for exiting I'm not sure how to handle it. I need some kind of event that will happen just prior to the loop completing.</p>
  
  <p>Is there any way to accomplish this?</p>
  
  <hr>
  
  <p>The reason I need this is for posting events to the thread. I have a function, a cleanup function in particular, say <code>cleanupObject</code>. This function can be called from any thread and is expected to do cleanup on the object. These objects are owned by a thread with an event loop. If this event loop is running this <code>cleanupObject</code> request has to be processed as an event in that event loop. If the event loop is not running then the cleanup has to be handled differently (this happens during shutdown).</p>
  
  <p>The race exists because <code>isRunning</code> has no synchronization I can use, so while it said true when I called it, it may not longer be running the instant after. I need to know whethere the event I post to the loop will be processed or not, because if it will not be processed I must do cleanup in a different fashion.</p>