Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio] Socket Read/Write Thread-Safety (TimothyLiang)
From: Timothy Liang (timothy003_at_[hidden])
Date: 2011-01-31 07:04:55


> RTFM. Really, RTFM.
> Use boost::asio::io_service::strand and don't worry about synchronization.
>
> http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/overview/core/strands.html
>
> You can use async_read and async_write simultaneously (but note "Thread
> Safety" for used asio class) with strands easily. Yes, with multiple
> threads running boost::asio::io_service::run on the same
> boost::asio::io_service object.
>
> What amazing laziness in reading asio docs :) - all of the latest
> questions about Boost.Asio have respective answers in documentation.
>
> Marat Abrarov.

Thanks for your reply. I've read the docs already, and didn't find a good
explanation. After a couple of days of searching, I got frustrated and
asked in the IRC channel. Still without an answer, I looked through the
docs again and then took the time to subscribe to this mailing list and type
up a detailed and concise question. And then waited patiently for the
moderators to review my mail for approval.

I think that page could present a better example. I did come across it, but
it used the term 'intermediate handler', which I thought was referring to
the completion-condition handler. It also didn't say that I had to directly
pass my wrapped handler to the composed operations as the completion
handler, without encapsulating it in another function object, which I was
doing since I thought that the wrapped handler type only served as a
functor. I wasn't aware that there was a hooking mechanism for all handlers
called by the io_service that used ADL to find custom invocation code. The
example on the page makes perfect sense now that I know about it, but I
couldn't for the life of me understand it before.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net