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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With