开发者

Does boost::asio::deadline_timer use a thread for each timer?

I have a list of items that I need to update on different intervals. The list can grow to be thousands of items long. Each item could potentially have a different interval. If I create 开发者_运维技巧one timer per item, am I going to saturate the system with threads? I was thinking it might be better to create one timer equal to the smallest interval in the set of items, and then on each update increment a counter, and then check to see if the counter is now equal to any other intervals. This should work provided the smallest interval is a multiple of all the other intervals. Any suggestions?


Boost does not use a thread per timer, it keeps a timer queue. Every timer is created with boost::asio::io_service object that does the actual work.

This object can dispatch its work in one or more threads, when you run boost::asio::io_service::run() explicitly from multiple threads, but there is no one-to-one correspondence between timers and threads, and Asio will not create threads behind your back.


Recent versions of Asio, Boost 1.43 and later, use the timerfd_create(2) API on Linux for deadline_timers.

Changed to use timerfd for dispatching timers on Linux, when available.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜