Synchronization problem with Interrupt Service Routine (ISR)

I would not implement it that way. You should not disable interrupts from the ISR. And the volatile keyword does not solve this issue either. This causes the compiler to not cache the result in a register, but does not prevent the situation where the ISR modifies the value while another thread is reading or writing it.

The method I use is std::atomic which does atomic operations on integer-like values without disabling interrupts, and is also thread and ISR safe.
Can the P2 run two Interrupts concurrently?

4 Likes