Let's say in the traditional producer/consumer pattern, the producer will produce two types of elements, A
& B
. The buffer queue should implement the following logics:
- Thread safe.
- FIFO
- All
A
can safely stay in the queue, which denote important task. - Whenever a new
B
arrive, kick out all preceedingB
in the queue and append to the end of the queue, which denote the latest non-important task. - The order of elements should be preserved.
- The consumer pop element just like normal.
For simplicity, just imagine the size of the queue is unlimited.
Is it possible to implement this without using 2 queues?