I'm using a static variable inside an interrupt handler, making the interrupt handler non-reentrant.
Thanks
PS. I'm using Linux. The programming language I'm using is C if it makes a difference.
Interrupt handlers in Linux need not be reentrant. When a given interrupt handler is executing, the corresponding interrupt line is masked out on all processors, preventing another interrupt on the same line from being received. Normally all other interrupts are enabled, so other interrupts are serviced, but the current line is always disabled.
If a function is reentrant then it can be "interrupted in the middle of its execution and then safely called again" ( Reentrancy (computing) ). If an interrupt handler is non-reentrant, then you could have undefined behavior if you receive another interrupt while your original interrupt handler is executing.
Interrupt handlers are initiated by hardware interrupts, software interrupt instructions, or software exceptions, and are used for implementing device drivers or transitions between protected modes of operation, such as system calls . The traditional form of interrupt handler is the hardware interrupt handler.
Reentrant is a function that can be called from an interrupt handler of an interrupt that interrupted the same function running previously. Thread-safe is a function that can run on several concurrent execution units at the same time. likes programming languages. Author has 309 answers and 1.9M answer views 5 y
The short answer is that Interrupt Service Routines are not inherently required to be reentrant. Reentrancy is only required in the case of nested interrupts. If the Operating System you use does not support nested interrupts, then you do not need to worry about reentrancy at all. If it does, you may have control over resetting the interrupt you are servicing so that you should never get a nested interrupt.
EDIT: Now that I know you're using Linux, you might find this link helpful: Can an interrupt handler be preempted by the same interrupt handler?
Essentially the answer to your question is that Linux masks an interrupt when it is asserted so that it won't preempt itself unless a specific flag is passed when registering the ISR.
Here's a relevant quote:
Interrupt handlers in Linux need not be reentrant. When a given interrupt handler is executing, the corresponding interrupt line is masked out on all processors, preventing another interrupt on the same line from being received. Normally all other interrupts are enabled, so other interrupts are serviced, but the current line is always disabled. Consequently, the same interrupt handler is never invoked concurrently to service a nested interrupt. This greatly simplifies writing your interrupt handler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With