On 7/09/2020 22:12, Richard Hodges wrote:
If your implementation is single threaded, you don't need to worry about concurrency issues at all. All completion handlers will be scheduled to run sequentially.
That's almost true. The one other place you need to be careful of is when initiating operations externally (usually writes, since reads are typically only initiated from completion handlers, but writes can come from both inside and outside). The best thing to do there is to not try to directly issue writes from "outside", but instead post() the request to start the write to the same io_context that's managing the socket. (The fundamental write operation itself doesn't really care which thread you start it from, but usually you'll want to manage other state variables in the class when initiating writes, and those can be protected by ensuring you only touch them from the io_context thread.)