title: Atomic Operation C++
body: <p>In C++, Windows platform, I want to execute a set of function calls as atomic so that execution doesn't switches to other threads in my process. How do I go about doing that? Any ideas, hints?</p>
  
  <p><strong>EDIT:</strong> I have a piece of code like:</p>
  
  <pre><code>someObject-&gt;Restart();
  
  WaitForSingleObject(handle, INFINITE);
  </code></pre>
  
  <p>Now the <strong>Restart()</strong> function does its work asynchronously, so it returns quickly and when that someObject is restarted it sends me an event from another thread where I signal the event handle on which I'm waiting and thus continue processing. But now the problem is that before the code reaches <strong>WaitForSingleObject()</strong> part, I receive the restart completion event and I signal the event and after that <strong>WaitForSingleObject()</strong> never returns since it is not signaled again. That's why I want to execute both <strong>Restart()</strong> and <strong>WaitForSingleObject()</strong> as atomic.</p>