<p>I have two system calls GetSystemTime() and GetThreadTimes() that I need to calculate the CPU utilization by a given Win32 thread.</p>

<p>For the sake of accuracy, I need to ensure that both GetSystemTime() and GetThreadTimes() are executed atomically; i.e. there should be no context switch in between a call to GetSystemTime() &amp; GetThreadTimes().</p>

<p>The reason is that occasionally I end up with a percentage of over 100% (~ 1 in 500).</p>

<p>How can I ensure an atomic execution of the 2 function calls?</p>

<p>Thanks,
Sachin</p>

I'm not so sure you can. Unless you know what the underlying operations are in each function, and since they happen to be Windows API calls... good luck.
Would it not be possible to just adjust for percentages over 100?
```
```
perc = ( perc > 100.0f ) ? 100.0f : perc;
```
```