难道是线程安全调用async_send和async_receive在同一时间? [英] Is it thread safe to call async_send and async_receive at the same time?
问题描述
我了解,调用提高:: ASIO ::知识产权:: TCP ::插座:: async_receive
(或的boost :: ASIO :: IP :: TCP ::插座:: async_send
)两次可能会导致不良行为..
它是确定的,如果我叫的boost ::支持ASIO ::知识产权:: TCP ::插座:: async_recive
和提高:: ASIO :: IP: :?TCP套接字:: :: async_send
同时
I understood that calling boost::asio::ip::tcp::socket::async_receive
(or boost::asio::ip::tcp::socket::async_send
) two times may result in a bad behavior..
Is it OK if i call boost::asio::ip::tcp::socket::async_recive
and boost::asio::ip::tcp::socket::async_send
at the same time?
我将有2个或多个线程运行的boost ::支持ASIO ::运行
所以你需要考虑到这一点。
I am going to have 2 or more threads running the boost::asio::run
so you need to take that into account..
感谢
推荐答案
这必须是确定。你怎么回事就在一个单一的服务进行全双工异步通信?你需要一个在任何时候传入数据接收突出。
This has to be OK. How else would you perform full duplex async communications on a single service? You need a receive outstanding at all times for incoming data.
借助加速文档仅指示每个 async_read
和 async_write
必须连续调用。例如, async_read
:
The Boost docs indicate only that each of async_read
and async_write
must be called serially. For example, for async_read
:
程序必须保证
流不执行任何其他读
操作(如async_read,该
流的async_read_some功能,或
任何其他操作组成的那
执行读取),直至该操作
完成。
The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.
为插座
的文档不特定在这一点上,这是真的。
The docs for socket
are not specific on this point, it's true.
这篇关于难道是线程安全调用async_send和async_receive在同一时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!