async_XXX() functions

I noticed that there are couple of async_XXX methods, such as async_wait, async_connect, async_write and async_fill. Just wondering why we need those async_XXX methods? without the "async", those methods will block the execution and next statements will be deferred. with the "async", those methods will return immediately and the work will be deferred a little time but will still be executed in the same thread. I feel it confuses people. If we need next statements being executed immediately, we can use another thread to do the wait, connect, write or fill. It is more clear and clean. And the user/programmer has fully control on this. Maybe I have missed something here. please give me your comments. thanks, James

On Sat, 31 May 2008 02:33:53 +0900, Longyu Mei
I noticed that there are couple of async_XXX methods, such as async_wait, async_connect, async_write and async_fill. Just wondering why we need those async_XXX methods?
I assume that you are referring to the library Boost.Asio?
without the "async", those methods will block the execution and next statements will be deferred. with the "async", those methods will return immediately and the work will be deferred a little time but will still be executed in the same thread.
Yes, that's the idea. :)
I feel it confuses people. If we need next statements being executed immediately, we can use another thread to do the wait, connect, write or fill. It is more clear and clean. And the user/programmer has fully control on this.
Depending on the operating system there might be more efficient APIs available as if you would need to use a thread for every blocking function (eg. you don't need 100 threads in a server with 100 connections if you use select()). I wouldn't necessarily agree either that using threads is always clearer and cleaner - just think about synchronizing them. As it might be necessary though to use a thread to make some functions support the asynchronous I/O model of Boost.Asio: That's completely transparent to the user. Even if there is a thread used in the background you don't need to worry about it as your code (the handlers) are executed in the same thread. The synchronization is done by Boost.Asio automatically - that I call clear and clean. :) Boris
participants (2)
-
Boris
-
Longyu Mei