Are these async_ * boost :: asio lib functions executed in parallel with the OS

I recently use boost :: asio library and ask a question about these async_ * functions.

Let's say I call several boost::asio::async_write() sequentially, is it possible that these async_write() functions are executed in parallel with the underlying operating system, even if io_service is single-threaded

Thanks!

+5
source share
1 answer

it is possible that these async_write () functions are executed in parallel with the underlying operating system

Yes they!
There are two types of asynchronous actions, CPU-bound tasks and IO-bound tasks.

CPU-related tasks are tasks that include only CPU execution, such as computing, reading and writing data to RAM, etc.

IO-related tasks are tasks related to reading and writing to devices, such as a hard disk (IO file), network card (network IO), etc.

To asynchronously perform tasks with a processor binding, you need multiple threads, but IO is different. Asynchronous IO does not use parallel streams, it simply queues a request to the appropriate device (hard disk, network card, etc.) and proceeds to execute another code without waiting for I / O to complete.

So, asynchronous IO (given, for example, boost As ynchronous IO ) will work in parallel even without multiple threads.

+5
source

Source: https://habr.com/ru/post/1258246/


All Articles