繁忙等待和轮询之间有什么区别? [英] What is the difference between busy-wait and polling?

查看:674
本文介绍了繁忙等待和轮询之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘录自投票

计算机科学中的轮询或轮询操作是指通过客户端程序主动采样外部设备的状态作为同步活动.轮询最常用于输入/输出(I/O),也称为轮询I/O或软件驱动的I/O.

Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity. Polling is most often used in terms of input/output (I/O), and is also referred to as polled I/O or software driven I/O.

有时将轮询与繁忙等待轮询(繁忙等待)同义使用.在这种情况下,当需要进行I/O操作时,计算机将只检查I/O设备的状态,直到准备就绪为止(此时可以访问该设备).换句话说,计算机将等待直到设备准备就绪.
轮询还指反复检查设备是否准备就绪的情况,如果不是,则计算机将返回其他任务.尽管不像忙等待那样浪费CPU周期,但是这通常不如轮询,中断驱动的I/O那样有效.

Polling is sometimes used synonymously with busy-wait polling (busy waiting). In this situation, when an I/O operation is required the computer does nothing other than check the status of the I/O device until it is ready, at which point the device is accessed. In other words the computer waits until the device is ready.
Polling also refers to the situation where a device is repeatedly checked for readiness, and if it is not the computer returns to a different task. Although not as wasteful of CPU cycles as busy-wait, this is generally not as efficient as the alternative to polling, interrupt driven I/O.

那么,当线程不使用条件变量"时,是否将其称为轮询"以进行数据更改或忙于等待"?

So, when a thread doesn't use the "condition variables", will it be called "polling" for the data change or "busy waiting"?

推荐答案

两者之间的区别在于应用程序在两次轮询之间的作用.

The difference between the two is what the application does between polls.

如果某个程序每秒轮询一次设备,并且在没有数据可用的同时(包括可能只是在休眠,而让CPU可供其他人使用)在此期间执行其他操作,则该轮询.
如果程序连续轮询设备(或资源或其他任何东西)而在两次检查之间不做任何事情,则称为忙等待.

If a program polls a device say every second, and does something else in the mean time if no data is available (including possibly just sleeping, leaving the CPU available for others), it's polling.
If the program continuously polls the device (or resource or whatever) without doing anything in between checks, it's called a busy-wait.

这与同步没有直接关系.阻塞条件变量的程序(应在设备或资源可用时发出信号)既没有轮询也没有繁忙等待.这更像是事件驱动/中断驱动的I/O.
(但是例如,围绕try_lock循环的线程是轮询的一种形式,如果循环太紧,可能会忙于等待.)

This isn't directly related to synchronization. A program that blocks on a condition variable (that should signal when a device or resource is available) is neither polling nor busy-waiting. That's more like event-driven/interrupt-driven I/O.
(But for example a thread that loops around a try_lock is a form of polling, and possibly busy-waiting if the loop is tight.)

这篇关于繁忙等待和轮询之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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