www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/02/22/15:32:14

Date: Mon, 22 Feb 93 15:16:44 EST
From: csa AT pennies DOT sw DOT stratus DOT com (Chris Arthur)
To: dmb AT ai DOT mit DOT edu
Subject: Re: Replacing arbitrary interrupt handlers
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019