Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can it be a loop with or without statements?

while (1)
{
   //Empty
}

OR

int i = 0;

while (1)
{
   i++;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
643 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...