中断处理程序可以写入 FIFO
我有一个线程正在等待 FIFO 上接收到的事件。 大多数事件是从同一进程中的另一个线程发送的配置事件。 我希望线程也能够通过让中断处理程序写入 FIFO 来处理中断事件,这可能吗?
欢迎任何其他建议而不是使用 FIFO!
I have a thread that is waiting for events received on a FIFO.
Most of events are configuration events send from another thread in the same process.
I would like the thread also to be able to handle interrupt events by having the interrupt handler writing to the FIFO is that possible?
Any other suggestion instead of using FIFO is welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以。使用中断处理程序是处理异步 I/O 的较新方法之一。
更典型的方法是使用 select、poll 或 Linux epoll 命令。
这些可以说是更优选的,因为您可以在事件可用时处理事件并返回到“轮询”循环以获取更多事件,而不是在事件可用时“中断”您的代码完成 与先前的事件。这些机制可以同时等待多个不同的文件描述符,并返回可用的文件描述符。
中断处理程序可能不是您想要做的 - 因为您不一定希望在处理一个事件时被中断,以知道另一个事件已准备好。如果这样做,您可能最终会将请求排队以供稍后处理 - 这正是 poll 和 epoll 的开始目的。
如果您使用的是 Linux,“epoll”是最佳选择。如果您不这样做(或者想要符合 POSIX 标准),请使用“poll”。 “select”是一种“较旧”的方法,并且也不对请求进行排队。
Yes, it can. Using interrupt handlers is one of the newer ways of handling asynchronous I/O.
The more typical way of doing this, is with a select, poll, or Linux epoll command.
These are arguably a bit more preferred, because rather than "interrupting" your code when an event is available - you are able to handle events and return to the "poll" loop to get more events when you're done with the prior event. These mechanisms can wait on a number of different file descriptors at the same time, and return whichever one is available.
An interrupt handler is probably not what you want to do - because you don't necessarily want to be interrupted while processing one event, to know that another is ready. If you did, you'd probably wind up queuing the request anyway for later handling - which is exactly what poll and epoll to to begin with.
If you're under Linux, "epoll" is the most optimum. If your not, (or want POSIX compliance), use "poll". "select" is an "older" method, and doesn't queue requests as well.