title: Deferred execution strategy in C++
body: <p>I have a callback implementation in which an unknown third party calls a function pointer in my code.</p>
  
  <p>However, an issue in a lot languages is triggering code after a function returns. For instance, when a callback is called and I have to delete the calling object (and, in this case, re-initialize it), returning from the callback would cause an exception.</p>
  
  <p>Assuming I cannot hook and that I do not own/cannot modify the code calling the callback, what is the best way to execute code after a function returns?</p>
  
  <p>The only real way I can think of doing this is to set up some sort of state machine and have a worker thread check the state. However, the issue I foresee with this is that of a race condition, where a callback is called between the time the reset callback returns and the point the calling object is reset.</p>
  
  <p>Is there any sort of functionality I'm not aware of, or would this be the most efficient way of achieving such a result?</p>