可移植库中的timer_create和TimerQueueTimer功能(如boost)
我编写了一个在 Linux 上运行的程序,并使用 sigevent 和 timer_create 以便以指定的频率定期调用回调函数。现在,我希望该程序是可移植的(Windows 和 Linux),因此实现这一目标的漫长方法是使用 #ifdefs 并使用 Windows 等效功能。
AFAIK,Windows 上的等效项是 TimerQueueTimer。
我知道这是一项操作系统服务,但就像线程一样,它可以通过 Boost C++ 等库进行移植。
问题是:你知道 Boost C++ 库、POCO 或其他受人尊敬的库中是否有这样的东西吗?
如果不存在,那么是否有什么因素阻止这种东西出现在便携式库中?
仅供参考,boost::asio::deadline_timer 不是我要找的,它必须是一个定期调用回调函数的服务,其精度与timer_create 和 TimerQueueTimer 相同。
I have written a program that runs on Linux and uses sigevent and timer_create in order to have a callback function being called perdiodically at a specified frequency. Now, I want the program to be portable (Windows and Linux), so the long way to do it is to use #ifdefs and use Windows equivalent functionality.
AFAIK, the equivalent on windows would be TimerQueueTimer.
I know this is a OS service, but just like thread, it can be made portable via a library like Boost C++.
The question is: do you know if there is such things in the Boost C++ library, or maybe in POCO or other respectable library?
If it is absent, then is there anything preventing the presence of such thing in a portable library?
FYI, boost::asio::deadline_timer is not what I am looking for, it must be a service that calls periodically a callback function with the same precision as timer_create and TimerQueueTimer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
POCO 有一个运行 TimerTask 的多线程 Timer 类。基本上,您可以使用计时器到期时想要执行的操作来重写 TimerTask 的 run() 方法。可以将多个任务添加到 Timer 对象中,该对象会生成一个线程来顺序运行所有挂起的任务。这些任务可以是一次性的,也可以是间隔重复的。
不确定它是否满足您的所有需求,但值得一看。
POCO has a multi-threaded Timer class that runs TimerTask(s). Basically you override a TimerTask's run() method with what you want to do when the timer expires. Multiple tasks can be added to the Timer object which spawns a thread to sequentially run all pending tasks. The tasks can be one-time or interval repeatable.
Not sure if it meets all of your needs but it is worth looking at.
我强烈推荐 ACE(自适应通信环境)。具体查看 ACE_Reactor 类和 ACE_Reactor::schedule_timer(...) 方法。
访问 Wiki 页面以获取有关 ACE 的更多一般信息。
或者直接进入官网
I would strongly recommend ACE (The Adaptive Communications Environment). Specifically look into the ACE_Reactor class and the ACE_Reactor::schedule_timer(...) method.
Visit the Wiki page for more general information about ACE.
Or go directly to the official website.