[Asio]About aync_write and socket.close()

Hi,All io_service_.run() in itself thread. I initial socket with it , like "socket_(io_service_)" . Then I read data from this socket in io_service thread. Now if i want call "async_write " to this socket in another thread, do I must use "io_service_.post( boost::bind function which call async_write)", or can I call async_write directly? And if i want close this socket, do I must use "io_service_.post(..)" , or can I use "socket_.close()" directly in another thread? thanks

On Fri, Nov 13, 2009 at 8:22 AM, victor
Hi,All io_service_.run() in itself thread. I initial socket with it , like "socket_(io_service_)" . Then I read data from this socket in io_service thread. Now if i want call "async_write " to this socket in another thread, do I must use "io_service_.post( boost::bind function which call async_write)", or can I call async_write directly? And if i want close this socket, do I must use "io_service_.post(..)" , or can I use "socket_.close()" directly in another thread?
thanks
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
You may call the methods directly from another thread. -- Matheus Araújo Aguiar Computer Scientist matheus.pit@gmail.com

hi,Matheus Araújo Aguiar
Thanks for your reply.
Is it a certain that it's thread-safety that call the methods directly
from another thread?
2009/11/14 Igor R
You may call the methods directly from another thread.
Could you elaborate how you reached this conclusion? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Sat, Nov 14, 2009 at 1:38 PM, Igor R
You may call the methods directly from another thread.
Could you elaborate how you reached this conclusion?
Sorry if i was too short. But i saw no problem calling the socket async write method from a different thread. The async write requests a write operation that's gonna be performed asynchronously and when the operation is complete, the io_service::run thread executes the appropriated handler. If you guarantee that only one thread at a time is calling the object's async method, there are no problems with it, i assume. Did i make a mistake(or more than one) in that reasoning?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Matheus Araújo Aguiar Computer Scientist matheus.pit@gmail.com
participants (3)
-
Igor R
-
Matheus Araújo Aguiar
-
victor