I have some high-concurrent message handler receiving ordered messages and now need to handle wrong ordered messages: if forward message arrive it should notify and if stale message arrive - it should ignore it.
Example: if 1,2,3,5 messages arrived - it must notify about missed message on 5th, and if 1,2,3,4,2,5 - it must notify only about stale message when receiving 2 after 4.
As it's high-throughput it mustn't use locks.
Here is my current implementation - https://codereview.stackexchange.com/q/10329/5334
-I've solved ABA problem but can't solve problem 1 possible false warning after ignoring stale messsages: on 1,2,3,4,2,5 - it'll notify about stale 2 (after 4) but can also wrongly notify about missed messages on 5th.
Are there ways to fix it or other non-blocking algorithms for this task?