I have a task that requires listening to multiple data source, and process the data to calculate some statistics (like cumulative sum of all data) for every new record coming in.
I am reading this post for a queue with condition variables. I wonder if this solution will work for multiple input scenario.
Say we have two listener thread A & B, and one consumer thread. Listener A calls the push function, gains and releases the lock, then notify the consumer with condition variable. Is it possible that Listener B will take over immediately as it has received data in the meantime, stopping the consumer from processing the new data introduced by A? How can one make sure that the consumer logic has ran exactly once whenever new data comes in, regardless of which listener it comes from?