c++ - Multiple async_wait from a boost Asio deadline_timer -


is possible call async_wait several times on same boost::asio::deadline_timer?

what mean following:

t->expires_from_now(delay); t->async_wait(f1); t->async_wait(f2); 

does ensures 2 functions called? ensures 2 functions called in order?

if not, idea how have f1 , f2 successively called when timer times out? (i don't care if handler executed between calls f1 , f2).

another question: if 2 timers t1 , t2 set such deadline of t1 before deadline of t2, can sure handler associated t1 called before handler associated t2? (in case above code, create second timer f2 delay larger delay set first timer).

thanks

carefully reading documentation on http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/basic_deadline_timer/async_wait.html, states that

for each call async_wait(), supplied handler called exactly once.

(emphasis mine). means in case, both f1 , f2 called once.

to second question: depends on 3 conditions:

  1. there might issues when expiration times differ short period below resolution of system clock (or of os'es timing service). behavior in case defined timer implementation (but should not problem default implementation boost, see comments).
  2. the possible concurrency of 2 handlers in multithreaded environments. wrap 2 handlers same strand issues related concurrency out of way.
  3. the possibility of cancellation of timers. when later timer gets cancelled before earlier timer expires, (by setting expiration time), fires handlers before earlier timer does.

update:
realized there second part in first question regarding order in handlers called. documentations not that. in implementation, may change.
in case want 2 functions executed in order, call second first one. if second handler should "appended" first 1 in conditions, either delay call async_wait until know whole extent of handler chain, or make them independent of each other.
third possibility roll own, appendable handler. bear in mind, handlers copied io_service::run thread, i.e. async_wait calls, appendable handler need pointer real chain of handlers, need take concurrency account , on.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -