支持重叠 I/O(对于 IOCP)的定时器?

发布于 2024-09-09 03:20:39 字数 525 浏览 5 评论 0原文

我需要在基于 I/O 完成端口 (IOCP) 的应用程序中添加计时器支持。我想避免使用特定线程来管理计时器。

在 Linux 上,您可以创建一个通过文件描述符传递过期通知的计时器(请参阅timerfd.h man),因此如果您的应用程序基于 epoll,那么将它与 epoll 一起使用是非常好的。

在 Windows 上,您可以将“可等待计时器”与异步过程调用 (ACP) 结合使用(请参阅 http://msdn.microsoft.com/en-us/library/ms686898(v=VS.85).aspx)

如果您有兴趣,kqueue(BSD、Mac OS )默认支持计时器(请参阅 EVFILT_TIMER)。

对于 I/O 完成端口,我们必须使用支持重叠 I/O 的对象。那么,IOCP有这样的定时器吗?

最好的问候,

塞德里克斯

I need to add timers support in an application based on I/O Completion Ports (IOCP). I would like to avoid the use of a specific thread to manage timers.

On Linux, you can create a timer that delivers expiration notifications via a file descriptor (see timerfd.h man), so it's great to use it for example with epoll if your application is based on epoll.

On Windows, you can use "waitable timers" with an asynchronous procedure call (ACP) (see http://msdn.microsoft.com/en-us/library/ms686898(v=VS.85).aspx)

If you are interested, kqueue (BSD, Mac OS) supports timers by default (see EVFILT_TIMER).

With I/O Completion Ports, we have to use objets that support overlapped I/O. So, is there such a timer for IOCP ?

Best regards,

Cédrics

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如若梦似彩虹 2024-09-16 03:20:39

据我所知,没有定时器在到期时生成 IOCP 完成。

你可以尝试Windows定时器队列; CreateTimerQueueTimer

我最终编写了自己的计时器队列,它确实使用额外的线程来运行计时器,因此它可能对您没有好处:请参阅此处 查看我使用 TDD 和完整单元测试实现队列的一系列文章。我正在实现具有相同接口的更高性能的 TimerWheel,但同样将使用外部线程来管理计时器。

As far as I know there are no timers that generate a IOCP completion when they expire.

You could try the Windows timer queue; CreateTimerQueueTimer.

I ended up writing my own timer queue which does use an extra thread to run the timers, so it's probably no good for you: See here for a series of articles where I implement the queue with TDD and full unit tests. I'm in the process of implementing a higher performance TimerWheel with the same interface, but again that will use an external thread to manage the timers.

深府石板幽径 2024-09-16 03:20:39

您可以使用可等待计时器,并使用“PostQueuedCompletionStatus”将自定义数据包排队到完成端口。但请记住,如果有多个工作线程,则只有其中一个线程会收到通知。

You could use waitable timers and queue a custom packet to the completion port using "PostQueuedCompletionStatus". But remember that if there are multiple worker threads only one of the thread will be notified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文