Boost logo

Boost Users :

Subject: [Boost-users] Why does `boost::asio::deadline_timer` allocate a `timer_queue` instance for each `deadline_timer` object?
From: Wang Danqi (beyondwdq_at_[hidden])
Date: 2014-11-15 10:24:38


Hi

I am looking into the implementation of `boost::asio::deadline_timer`,
based on boost 1.52.

As described in [the article on
highscore](http://en.highscore.de/cpp/boost/asio.html#asio_extensions),
it is implemented in three parts:

* `deadline_timer`, the i/o object
* `deadline_timer_service`, the service
* `detail::deadline_timer_service`, the service implementation

There will be a single instance of `deadline_timer_service` serving
many `deadline_timer` objects. An instance of
`detail::deadline_timer_service` is created for each `deadline_timer`
object. Moreover, the timers are scheduled by a scheduler, which is
usually a reactor (i.e. `epoll_reactor` on Linux in most cases).

There is a `timer_queue_` member of type `timer_queue` in
`detail::deadline_timer_service` which is a heap that stores scheduled
timers. This means that there will be one instance of `timer_queue`
for each `deadline_timer` object. Multiple `timer_queue` objects can
be added to the scheduler by `add_timer_queue()`, and they are managed
by a class `timer_queue_set`.

My question is, why `asio` create multiple queues to handle timers?
What is the drawback if we have a single timer queue instance in the
scheduler that all timers can share?

Please note that I am asking about the `boost::asio::deadline_timer`,
not the example in the highscore link.

I have posted this question on stackoverflow previously
[here](http://stackoverflow.com/q/26922754/930095)

-- 
Best wishes,
Wang Danqi

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net