c++ - BOOST ASIO multi-io_service RPC framework design RFC -
i working on rpc framework, want use multi io_service design decouple io_objects perform io (front-end) the threads perform rpc work (the back-end).
the front-end should single threaded , back-end should have thread pool. considering design front-end , back-end synchronise using condition variables. however, seems boost::thread , boost::asio not comingle --i.e., seems condition variable async_wait support not available. have question open on matter here.  
it occured me io_service::post() might used synchronise 2 io_service objects. have attached diagram below, want know if understand post mechanism correctly, , weather sensible implementation.

i assume use "a single io_service , thread pool calling io_service::run()"
also assume frond-end single-threaded avoid race condition writing multiple threads same socket.
the same goal can achieved using io_service::strand (tutorial).your front-end can mt synchronized io_service::strand. posts back-end front-end (and handlers front-end front-end handle_connect etc.) should wrapped strand, this:
back-end -> front-end:
io_service.post(front_end.strand.wrap(     boost::bind(&front_end::send_response, front_end_ptr)));   or front-end -> front-end:
socket.async_connect(endpoint, strand.wrap(     boost::bind(&front_end::handle_connect, shared_from_this(),      boost::asio::placeholders::error)));   and posts front-end back-end shouldn't wrapped strand.
Comments
Post a Comment