开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Flushing the Incoming Message Buffer - C++ Multi-threading


 

I have a C++ GUI application which on which at a user request, the list of symbols will be cleared and all the market data requests will be cancelled, and ultimately the buffer holding the records for the GUI display is cleared.

The issue I have is that every now and again I get a crash because there are still incoming tick messages (price, volume, etc.) in the queue after the display and buffer are cleared.

Is there any way I can test the incoming message queue to see if there are any messages to process? Is there a way to clear that queue to prevent further GUI update calls from the reader thread?


 

On Tue, Jul 26, 2022 at 06:09 PM, David Armour wrote:
after the display and buffer are cleared.
...this means that this is also after all the market data subscriptions have been cancelled.


 

Even after you cancel a request there may be messages wandering around the Internet that may appear many seconds later.

You need to accept any message at any time. If you receive tick data you're no longer interested in then you need to ignore.it.


 

Thanks Hilmar.

After digging into the API code and seeing how the messages were handled I realised the answer to my question was "NO" it is not possible. Also, as you mention, checking/clearing the message deque would not be sufficient if the messages hadn't even arrived yet.


I have modified my model to cater for such "late" data and so far so good. It meant adding a mutex around the display buffer (separating updates from clearing) which might impact code speed but doesn't really matter since this is all user interface stuff.