Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timer that supports overlapped I/O (for 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

like image 245
Cédrics Avatar asked Jul 13 '10 16:07

Cédrics


1 Answers

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.

like image 166
Len Holgate Avatar answered Sep 22 '22 13:09

Len Holgate