支持重叠 I/O(用于 IOCP)的定时器? [英] Timer that supports overlapped I/O (for IOCP)?

查看:34
本文介绍了支持重叠 I/O(用于 IOCP)的定时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在基于 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.

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

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.

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

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)

如果你有兴趣,kqueue (BSD, Mac OS) 默认支持定时器(参见 EVFILT_TIMER).

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

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

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

最好的问候,

塞德里克

推荐答案

据我所知,没有计时器会在它们到期时生成 IOCP 完成.

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

您可以尝试使用 Windows 计时器队列;CreateTimerQueueTimer.

You could try the Windows timer queue; CreateTimerQueueTimer.

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

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.

这篇关于支持重叠 I/O(用于 IOCP)的定时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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