Hi! I've an application to which a GUI connects and receives a lot of messages and the problem is that every once in a while it receives a message out of order.
The connection runs on a separate worker thread (a separate io_service) and exposes the "send" function(which does a async__write) via io_service::wrap as a callback for others to invoke with a string message as parameter. (i.e. callback = io_service_.wrap(boost::bind(&SomeGUIClass::send,this,_1)); ),
so to send something to the GUI client, the others call callback(stringMessage) - which should correctly dispatch the send function call on the io_service's queue.
messages are in correct order before invoking the callback, but I can see that sometimes they are out of order within the callback,just before the write call.
my reasoning: wrap translates to a 'dispatch' which will try to call the wrapped fn. within the callback(if it can meet the thread safety guarantees) , and schedule it for later if it cannot. thus sometimes earlier messages get scheduled for a later write and the latest messages get processed since dispatch was able to process it within the same callback. please let me know if this reasoning is correct, any ideas appreciated. thanks!