我们假设我想发送3个缓冲区:
Buffer1: 1111111111 Buffer2: 2222222222 Buffer3: 3333333333
我不介意缓冲区是否以错误的顺序发送,所以
333333333311111111112222222222
没问题,但缓冲内容是否可能完全混合在一起?
122213121212122333313111223333
PS:我100%肯定有人已经以某种形式问过这个……
解决方法
Both send and receive operations can
be overlapped. The receive functions
may be invoked multiple times to post
receive buffers in preparation for
incoming data,and the send functions
may be invoked multiple times to queue
up multiple buffers to be sent. Note
that while a series of overlapped send
buffers will be sent in the order
supplied,the corresponding completion
indications may occur in a different
order. Likewise,on the receiving
side,buffers will be filled in the
order they are supplied,but
completion indications may occur in a
different order.
毫不奇怪,同样的保证会延续到世界的管理方面,例如. NetworkStream
班:
Read and write operations can be
performed simultaneously on an
instance of the NetworkStream class
without the need for synchronization.
As long as there is one unique thread
for the write operations and one
unique thread for the read operations,
there will be no cross-interference
between read and write threads and no
synchronization is required.
话虽这么说,在Stream上随机抛出异步读写会很快导致混乱.应用程序需要仔细协调线程提交操作的顺序,以使订单具有确定性.通常这意味着在保持同步锁的同时特别注意在(同步)列表中进行记帐以执行异步操作调用.
最后要注意的是,所有这些异步API都在特别说明,确保完成顺序不能保证与提交顺序相匹配.