Quote:
|
Originally Posted by eugenebrooks
There is a hazard associated with reading a counter value that is maintained by the interrupt handler
|
Eugene is referring to one of the problems with using interrupts (and multitasking systems in general). The code in clock.c assumes that the timer 2 interrupt service routine won't update the value of "Clock" while the function Display_Time() accesses it. For this example the chances of this happening is pretty slim. In general this is something that should be taken into consideration to prevent a race condition. Possible solutions include briefly disabling interrupts while the variable is accessed or using a synchronization mechanism like a semaphore. There's lots of information about this topic on the web.
Another possible problem is when the variable can be modified through some process the compiler doesn't know about. You can inform the compiler of this possibility by using the keyword "volatile" in the variable's declaration. There's also much information about the volatile keyword on the web.
-Kevin