Skip to content
Advertisement

Why boost::aio is asynchronous when its implementation is based on epoll(synchronous)

We know:

(1) epoll is synchronous, based on user query/system notify. A while loop is used to call all woke up fds.

(2) boost::asio declares itself to be “asynchronous”, but its implementation on linux is using epoll.

My question is: how can you implement “asyn” using a “syn” system call? Unless you use some kernel/system supported aio interface, right?

Please help to correct my confusions. Thanks!

Advertisement

Answer

“synchronous” normally refers to an operation that does not return control back to the caller until it has completed.

epoll is synchronous in the sense that its operation (returning fds with pending completions/actions) is complete by the time it returns.

Reading from or writing to a socket however is still asynchronous in the sense that the operation to read or write is still not complete when the function call returns. The actual I/O work may be done asynchronously, and epoll will tell you when it’s done. The work will be performed regardless of if and when you call epoll, epoll is just the mechanism to signal completions back to you, not the function that performs the work.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement