Hi Vincente,
On Wed, May 1, 2013 at 11:42 PM, Vicente J. Botet Escriba
I have just read N3388 - Using Asio with C++11 and a think I start to understand the ASIO design. Could we say the completion handlers are continuations? And that the user use to master which thread executes the continuation by calling the io_service::run() function?
Pretty much, except that multiple threads can call io_service::run concurrently. Basically Boost.Asio is a work sharing queue plus a collection of waitqueues to wait for specific events.
And that io_service can have associated also several threads (to form a thread pool).
The associated threads are exactly those that are currently calling io_service::run.
And that in order to avoid data races the user uses strands to serialize the completion handlers that have access to shared data?
That's one way, but not the only way.
While continuation passing style could be well adapted to protocols (and surely it is) , there are other domains that would prefer to write his code in a more linear way. It is true that with C++11 lambdas the continuation passing style is less opaque.
That's orthogonal. Boost.Asio provides the funding blocks. A nicer interface that doesn't require an explicit continuation passing style transformation can be built with Boost.Context or a similar library. But it probably needs a future implementation that integrates with ASIO, which is one of the point of Niall Douglas. See the recent discussion about "library support for async/await pattern". -- gpd