[asio-users] Composed operations not always atomic with strands
Brought to you by:
chris_kohlhoff
|
From: Bjorn R. <br...@ma...> - 2014-04-23 12:26:28
|
I am using async_write() together with a strand in a multi-threaded program in the same way as in the HTTP server 3 example. Under heavy load the async_write() operation ceases to be atomic (i.e. data send by one operation may be interleaved by data from another.) I have created the attached test case to illustrate the problem. Here I have two threads sending blocks of data on the same socket. The receiver is single-threaded, but I have added a sleep() to simulate slow processing. When the TCP buffer on the receiver side is full, the sender will only send part of the data. While the rest will be sent eventually, the problem is that data submitted by the other thread may be sent inbetween, so the data is received in the wrong order. The receiver will assert if this is the case. Before I create a ticket for this, can anybody find any errors in my attached examples? |