Concurrency issues with circular buffer in embedded program
If your queue has exactly one producer and one consumer make sure consumer has higher priority at all times. After this is achieved the concurrency won't cause any issues. Implementation depends on the hardware used, here's (my) code using such a queue on PIC24 micro -> https://github.com/felis/lcdtune/blob/master/lcdtune.c . The queue, as well as head and tail are defined here -> https://github.com/felis/lcdtune/blob/master/lcdtune.c#L50 , the producer is here -> https://github.com/felis/lcdtune/blob/master/lcdtune.c#L233 , and the consumer (the ISR) is here -> https://github.com/felis/lcdtune/blob/master/lcdtune.c#L102