On Wed, 2 Sep 2020 at 06:59, lampahome <pahome.chen@mirlab.org> wrote:


Richard Hodges via Boost-users <boost-users@lists.boost.org> 於 2020年9月1日 週二 下午6:54寫道:
Asio certainly has support for asynchronous file IO. I have used it on linux systems for a multitude of file handle types, including console I/O.

 Is there any function can handle the finished IO operation?

Assume I have two threads. One is only submit async io to file, and another one is only handle event of those executed io.
I only find handler function but wonder if any easier handler to handle all.

I'm not quite sure why you'd need two threads. But if you did, asio allows you to bind handlers to executors prior to submission to asynchronous initiating functions.
The handler will be executed by its associated executor, which could if you require be running in a different thread.

e.g.

async_write(f, buf, asio::bind_executor(other_executor, 
 [](error_code ec, std::size_t written) {
    // handler now executed by other_executor
 });

 If submitting across threads you'd want to be sure to protect access to the file object with a mutex or a strand.

 

thanks


--
Richard Hodges
office: +442032898513
home: +376841522
mobile: +376380212