boost::asio, threads and synchronization

前端 未结 4 1578
悲哀的现实
悲哀的现实 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:25

    1) Have a look at io_service::work. As long as an work object exists io_service::run will not return. So if you start doing your clean up, destroy the work object, cancel any outstanding operations, for example an async_read on a socket, wait for run to return and clean up your resources.

    2) io_service::post will asynchronously execute the given handler from a thread running the io_service. A callback can be used to get the result of the operation executed.

    3) You needs some form of messaging system to inform your GUI thread of the new data. There are several possibilities here.

    As far as your remark about the documention, I thing Asio is one of the better documented boost libraries and it comes with clear examples.

提交回复
热议问题