Can I share boost::asio::tcp::socket object between 2 threads that perform read and write

微笑、不失礼 提交于 2019-12-30 10:06:43

问题


I have two threads, one sending and another receiving data via TCP socket. I use boost::asio::read() and boost::asio::write() for reading and writing. My question is do I have to guard the access to socket object during read and write operation?

The other case would be what if I have two threads both writing using the same socket object?


回答1:


The socket is not thread safe when shared between two or more threads. For more information look at the Boost.Asio documentation.



来源:https://stackoverflow.com/questions/6941626/can-i-share-boostasiotcpsocket-object-between-2-threads-that-perform-read

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!