title: C++ Creating an atomic function
body: <pre><code>void foo ( Bar* bar , void(Bar::*qux)(void) )
  {
      if ( bar )
      {
          bar-&gt;qux();
      }
  }
  </code></pre>
  
  <p>The problem is:</p>
  
  <ol>
  <li><p><code>bar</code> can be deleted <strong>after</strong> the check by another thread.</p></li>
  <li><p>I can not add a mutex member to <code>Bar</code> in order to lock it.</p></li>
  </ol>
  
  <p>Thus I wonder, if I can tell the processor to run this function atomically, and how would I do so? I've spent way to much time on Google, but found no understandable manuals... </p>
  
  <p>P.S. Debian, gcc , Boost <strong>NOT</strong> allowed, C++11 <strong>IS</strong> allowed.</p>