View Single Post
  #5   Spotlight this post!  
Unread 02-12-2004, 03:36
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Is there a built in tick/millisecond counter?

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
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org