boost::asio, threads and synchronization

前端 未结 4 1580
悲哀的现实
悲哀的现实 2021-02-05 21:58

This is somewhat related to this question, but I think I need to know a little bit more. I\'ve been trying to get my head around how to do this for a few days (whilst working o

4条回答
  •  醉酒成梦
    2021-02-05 22:24

    boost::io_service::run() will return only when there's nothing to do, so no async operations are pending, e.g. async accept/connection, async read/write or async timer wait. so before calling io_service::run() you first have to start any async op.

    i haven't got do you have console or GUI app? in any case multithreading looks like a overkill. you can use Asio in conjunction with your message loop. if it's win32 GUI you can call io_service::run_one() from you OnIdle() handler. in case of console application you can setup deadline_timer that regularly checks (every 200ms?) for user input and use it with io_service::run(). everything in single thread to greatly simplify the solution

提交回复
热议问题