What is the difference betweeninterrupt-driven I/O versus pollingI/O

本文探讨了输入输出设备与CPU速度的巨大差距下,如何高效处理I/O操作的问题。通过对比轮询I/O和中断驱动I/O两种方式,阐述了它们的工作原理及优缺点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

quote from:http://www.calvin.edu/academic/rit/webBook/chapter2/design/hardware/io/interrupts.htm

What is the difference betweeninterrupt-driven I/O versus pollingI/O?

Most inputand output devices are much slower than the CPU—so much slower thatit would be a terrible waste of the CPU to make it wait for theinput devices. For example, compare the speed you can type with thespeed the CPU can execute instructions. Even a very fast typistcould probably type no more than 10 characters per second, while amodern CPU can execute more than two billion instructions in thatsame second!

Polling
If the CPU simply waits for the next input character, we call thispolled I/O. In this method, the CPU continuously polls the I/Odevice in a program loop, waiting for the next input. Think of agame where a basketball player is asked to make as many free-throwsas possible in one minute, but the clock is down the hall inanother room. The player must run down the hall and check if theminute has passed, and if not, go back to the gym and try to makeanother shot, then run down the hall to check the clock and runback to take another shot. The player spends much of the timesimply checking (polling) the clock.

Interrupts
An alternative scheme for dealing with I/O is the interrupt-drivenmethod. Here the CPU works on its given tasks continuously. When aninput is available, such as when someone types a key on thekeyboard, then the CPU is interrupted from its work to take care ofthe input data. In our example, the basketball player would takeshots one after another, while a second person watched the clockdown the hall. When the clock reached one minute, the personwatching the clock would yell down the hallway for the player tostop. This allows the player to take many more shots, but at theexpense of needing someone to watch the clock. Similarly, the CPUcan work continuously on a task without checking the input devices,allowing the devices themselves to interrupt it as necessary. Thisrequires some extra "smarts" in the form of electronic circuitry atthe I/O devices so that they can interrupt the CPU.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值