Meaning
Software instruction sequence that cannot be safely interrupted and executed again by another thread or interrupt handler before its initial execution finishes. When non-reentrant code is used, concurrent access to the same resources causes data corruption. This occurs because the routine relies on shared global state or static variables.
It is typical in legacy embedded drivers and unsynchronized peripheral access routines.
Risk Factor
If a hardware interrupt occurs while a function is writing to a global data array, the interrupt service routine might call that same function. When this happens, the newly called routine modifies the global pointers. Once the interrupt finishes and the original routine resumes, it processes corrupted or out-of-bounds array indices.
This leads to system crashes or unpredictable behavior.
Mitigation Strategy
Eliminating this vulnerability requires storing all temporary data on the stack rather than in static or global memory blocks. Developers can also protect critical sections by disabling interrupts or using reentrant mutex locks. Reentrant code relies exclusively on local variables passed by value on the stack.
This design guarantees that each executing thread has its own isolated memory workspace.
Verification Routine
Static analysis tools scan the source code during compilation to flag functions that modify non-local variables. These tools verify thread safety before hardware deployment.