Quantcast

Is boost::asio::ip::tcp::iostream thread safe?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Is boost::asio::ip::tcp::iostream thread safe?

boost-10

hi all,

I use ip::tcp::iostream but I don't know if it is thread safe, and I cannot find the answer in boost document. 

I read from ip::tcp::iostream in the receiver thread, and send request in another thread. 
Now I protected the stream with a mutex. But the problem is that, if I do not send request, the server will not response, 
and the receiver will block on read with lock, and the sender cannot hold the lock and cannot send the request, deadlock.


Is there anyone know that? Please kindly give me an answer.

Best Regards
Zhanwei Wang


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is boost::asio::ip::tcp::iostream thread safe?

Igor R.
> hi all,
> I use ip::tcp::iostream but I don't know if it is thread safe, and I cannot find the answer in boost document.
> I read from ip::tcp::iostream in the receiver thread, and send request in another thread.
> Now I protected the stream with a mutex. But the problem is that, if I do not send request, the server will not response,
> and the receiver will block on read with lock, and the sender cannot hold the lock and cannot send the request, deadlock.
>
> Is there anyone know that? Please kindly give me an answer.


As far as I can see, it's not thread-safe.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is boost::asio::ip::tcp::iostream thread safe?

Michael Chisholm
On 5/10/2012 10:38 AM, Igor R wrote:

>> hi all,
>> I use ip::tcp::iostream but I don't know if it is thread safe, and I cannot find the answer in boost document.
>> I read from ip::tcp::iostream in the receiver thread, and send request in another thread.
>> Now I protected the stream with a mutex. But the problem is that, if I do not send request, the server will not response,
>> and the receiver will block on read with lock, and the sender cannot hold the lock and cannot send the request, deadlock.
>>
>> Is there anyone know that? Please kindly give me an answer.
>
>
> As far as I can see, it's not thread-safe.
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

Definitely not.  I had to create my own socket-based stream with
boost.iostreams to avoid crashes.

Andy

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is boost::asio::ip::tcp::iostream thread safe?

Michael Chisholm
On 5/10/2012 5:34 PM, Michael Chisholm wrote:

> On 5/10/2012 10:38 AM, Igor R wrote:
>>> hi all,
>>> I use ip::tcp::iostream but I don't know if it is thread safe, and I
>>> cannot find the answer in boost document.
>>> I read from ip::tcp::iostream in the receiver thread, and send
>>> request in another thread.
>>> Now I protected the stream with a mutex. But the problem is that, if
>>> I do not send request, the server will not response,
>>> and the receiver will block on read with lock, and the sender cannot
>>> hold the lock and cannot send the request, deadlock.
>>>
>>> Is there anyone know that? Please kindly give me an answer.
>>
>>
>> As far as I can see, it's not thread-safe.
>> _______________________________________________
>> Boost-users mailing list
>> [hidden email]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>
> Definitely not. I had to create my own socket-based stream with
> boost.iostreams to avoid crashes.
>
> Andy

I should add that boost.iostreams isn't thread-safe either.  But you can
create different istream and ostream objects which wrap the same
underlying raw socket descriptor, to get concurrent reads and writes to
the socket.

Andy

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is boost::asio::ip::tcp::iostream thread safe?

boost-10
In reply to this post by Igor R.
Thank you all
----- Original Message -----From: Michael Chisholm <[hidden email]>
To: [hidden email]

On 5/10/2012 5:34 PM, Michael Chisholm wrote:
> On 5/10/2012 10:38 AM, Igor R wrote:
>>> hi all,
>>> I use ip::tcp::iostream but I don't know if it is thread safe, and I
>>> cannot find the answer in boost document.
>>> I read from ip::tcp::iostream in the receiver thread, and send
>>> request in another thread.
>>> Now I protected the stream with a mutex. But the problem is that, if
>>> I do not send request, the server will not response,
>>> and the receiver will block on read with lock, and the sender cannot
>>> hold the lock and cannot send the request, deadlock.
>>>
>>> Is there anyone know that? Please kindly give me an answer.
>>
>>
>> As far as I can see, it's not thread-safe.
>> _______________________________________________
>> Boost-users mailing list
>> [hidden email]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>
> Definitely not. I had to create my own socket-based stream with
> boost.iostreams to avoid crashes.
>
> Andy

I should add that boost.iostreams isn't thread-safe either.  But you can 
create different istream and ostream objects which wrap the same 
underlying raw socket descriptor, to get concurrent reads and writes to 
the socket.

Andy

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Loading...