What is a busy loop?

后端 未结 3 1764
粉色の甜心
粉色の甜心 2020-12-21 16:41

Can it be a loop with or without statements?

while (1)
{
   //Empty
}

OR

int i = 0;

while (1)
{
   i++;
}
3条回答
  •  独厮守ぢ
    2020-12-21 17:36

    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.

提交回复
热议问题