基于轮询或中断的方法 [英] Polling or Interrupt based method

查看:25
本文介绍了基于轮询或中断的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候应该使用轮询方法,什么时候应该使用基于中断的方法?有没有可以同时使用的场景?

When should one use polling method and when should one use interrupt based method ? Are there scenarios in which both can be used ?

推荐答案

如果感兴趣的事件是:

  1. 异步
  2. 紧急
  3. 不常见

那么基于中断的处理程序就有意义了.

then an interrupt based handler would make sense.

如果感兴趣的事件是:

  1. 同步(即你知道什么时候在一个小窗口内期待它)
  2. 不紧急(即缓慢的轮询间隔没有不良影响)
  3. 频繁(即您的大多数轮询周期都会产生命中")

那么轮询可能更合适.

其他注意事项包括您是为操作系统编写设备驱动程序,还是仅编写不支持线程的裸机代码.在裸机情况下,CPU 通常只是在不忙的时候循环,所以它还不如轮询一些东西.

Other considerations include whether you are writing a device driver for an OS or just writing bare metal code with no thread support. In bare metal situations the CPU is often just looping when it isn't busy so it might as well be polling something.

这篇关于基于轮询或中断的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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