什么是忙循环? [英] What is a busy loop?

查看:193
本文介绍了什么是忙循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它可能是一个有或没有语句的循环吗?

Can it be a loop with or without statements?

while (1)
{
   //Empty
}

OR

int i = 0;

while (1)
{
   i++;
}


推荐答案

忙循环或更常见的是,繁忙等待是一种主动轮询,在该轮询中,应用程序正在等待某个事件的发生,并不断对其进行检查。通常,这包括定时睡眠或其他会浪费CPU时间的任务,以便另一个进程可以提供预期的输入。

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.

将此与回调进行对比。在等待回调时,程序不占用任何CPU周期。通常,程序会注册一个回调例程,某些监视应用程序会根据某些事件调用该回调例程。

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.

区别在于,繁忙循环中的程序会占用CPU和时间。回调机制允许程序在等待时不消耗(或几乎不消耗)CPU。

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.

这篇关于什么是忙循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆