Can it be a loop with or without statements?
while (1)
{
//Empty
}
OR
int i = 0;
while (1)
{
i++;
}
Can it be a loop with or without statements?
while (1)
{
//Empty
}
OR
int i = 0;
while (1)
{
i++;
}
A "busy loop" or more commonly "busy wait" is an active polling where the application is waiting on some event to occur and continuously checks for it. Typically this includes a timed sleep or other task which gives up CPU time so that another process can provide the expected input.
Contrast this with a callback. While waiting on a callback, the program consumes no CPU cycles. Typically the program will "register" a callback routine which some monitoring application invokes based on some event.
The distinction is that the program in a busy-loop consumes CPU and time slices while waiting while the callback mechanism allows a program to consume no (or almost no) CPU while waiting.
To me, a busy loop is a loop that never blocks.
Blocking is a behavior provided by the operating system that allows a thread to consume NO cpu cycles until some condition is met (a condition variable is signaled, or perhaps just data arriving on a socket (as recv() will block)).
In a traditional Win32 main loop, you potentially block every time your thread calls GetMessage(). All event driven windowing system are similar in this way.
I'm pretty sure you're talking about busy wait where you have a loop polling for some condition every iteration.