Mail Archives: djgpp/1993/02/22/15:32:14
> From: David Baggett <dmb AT case DOT ai DOT mit DOT edu>
> ...
>
> 1. In my timer interrupt I just update a global counter. I run my
> interrupt at 5 times the normal rate and then chain to the old
> vector every 5th time to keep things kosher for DOS. However, it
> seems that if I busy wait on the timer variable it doesn't get
> updated! E.g., the code
>
> for (;;) {
> if (ticks > 100)
> break;
> }
> ...
>
> Does anyone have any clue why this might be happening? (It seems
> awfully bizarre to me.)
Try declaring "ticks" as volatile. The problem is that gcc has no clue
that something might change the variable behind the compiler's back, so
it looks at the loop, determines that ticks can never change inside it,
and optimizes it into an endless loop. (Check the generated code; it
should bear me out.) Adding a call to a function defeats that optimization
if ticks is an external variable, because the compiler has to assume
that the function might modify ticks.
chris
- Raw text -