# Do we really need a fence event?

One of the hardest things for me with the modern closer to the metal graphics APIs is understanding synchronization. I usually try to simplify things in order to understand the concept better.

In Directx12, we can use a set of "x" fences (x being the number of back buffers) to allow the CPU to work ahead of the GPU. This could be the code we use to wait for a previous fence (https://www.braynzarsoft.net):

if (fence[frameIndex]->GetCompletedValue() < fenceValue[frameIndex])
{
hr = fence[frameIndex]->SetEventOnCompletion(fenceValue[frameIndex], fenceEvent);
if (FAILED(hr))
{
Running = false;
}
WaitForSingleObject(fenceEvent, INFINITE);
}


Is there a reason why we can´t just:

while(fence[frameIndex]->GetCompletedValue() < fenceValue[frameIndex])
{
}


Thanks!

In your first example, the call to WaitForSingleObject blocks the thread. This puts it into a waiting state, which takes it off the run queue and allows other threads to run on this CPU core. If no threads can run, the CPU will idle. When the fenceEvent completes, it wakes up this thread.