Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost.asio] Is it safe to call write() and async_read at the same time?
From: Viatcheslav.Sysoltsev_at_[hidden]
Date: 2011-05-12 02:32:16


On Wed, 11 May 2011 11:23:08 +0200, Igor R <boost.lists_at_[hidden]> wrote:

>> Is it safe to do the following in boost.asio? If it matters, I am
>> using a serial port at the moment, but the code will be used for
>> sockets as well. If not, what is the proper way to implement this to
>> get full duplex communication?
>>
>> Thread 1:
>> write(conn, buffer1)
>>
>> Thread 2:
>> async_read(conn, buffer2)
>
>
> It is safe to read from a socket, when there's a pending write. It is
> not safe to access the socket object simultaniously from multiple
> threads.

Hmmm, are you sure? I've thought pthread sockets are thread-safe. Or do
you mean boost layer over pthread sockets not being thread-safe? Anyway,
regarding the original question I believe the asio sockets must be
full-duplex, otherwise it'd be quite a step back over pthread
implementation and IMO bug report worthy.

-- Slava


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