What constraints apply to C++ code in an ISR, and how should data be handed off safely to normal execution?
Show answer and explanation
An interrupt service routine should perform bounded, minimal work, avoid blocking, allocation, non-reentrant library calls, and locks that normal execution might hold, then acknowledge the device as required. Data is normally handed off through a platform-approved lock-free flag or ring buffer, an RTOS ISR-safe primitive, or another mechanism whose atomicity and memory ordering are documented for that target. Volatile alone does not synchronize with normal code, and even a standard atomic must be verified as lock-free and usable in that interrupt environment.
An interrupt service routine should perform bounded, minimal work, avoid blocking, allocation, non-reentrant library calls, and locks that normal execution might hold, then acknowledge the device as required. Data is normally handed off through a platform-approved lock-free flag or ring buffer, an RTOS ISR-safe primitive, or another mechanism whose atomicity and memory ordering are documented for that target. Volatile alone does not synchronize with normal code, and even a standard atomic must be verified as lock-free and usable in that interrupt environment.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.