First page Back Continue Last page Overview Text


Suppose that a subroutine holds data in global variables. If Task A is executing a subroutine when an interrupt occurs, and subsequently Task B enters the subroutine, data may be lost. For example if Task A has just loaded a number 5 into a global variable when the interrupt occurs and then Task B loads a 9 into the same global variable, when Task A resumes execution, the wrong value will be held in the global variable.

Local variable in stack may be created when a subroutine is called. If the subroutine creates and loads a local variable, and it is interrupted and called again from the interrupting thread, another copy of the local variable will be created to hold the new data. By using local variables, when the original task resumes execution, all data will be intact.