Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are those async_* functions of boost::asio lib executed parallelly by OS

Recently I'm using boost::asio library, and have a question about those async_* functions.

Say I call multiple boost::asio::async_write() consecutively, is it possible that these async_write() functions executed parallelly by the underlying operating system even if io_service is run single-threadedly

Thanks!

like image 487
Chen Rushan Avatar asked Oct 15 '16 08:10

Chen Rushan


1 Answers

is it possible that these async_write() functions executed parallelly by the underlying operating system

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

CPU-bound tasks are tasks that involve only CPU-execution, like calculations, reading and writing data to the RAM, etc.

IO-Bound tasks are tasks that involve reading and writing to devices, like the Hard-disk (file IO) , network card (network IO) etc.

In order to asynchronously execute CPU-bound tasks you need multiple threads but IO is different. Asynchronous IO does not utilize threads to be parallel, it just queues a request to the relevant device (Hard-disk, networking card etc.) and moves on to execute another code, without waiting for the IO to finish.

So yes, asynchronous IO (given, for example, by boost Asynchronous IO) will still work in parallel even without multiple threads.

like image 183
David Haim Avatar answered Sep 23 '22 17:09

David Haim