C and real hardware

utzoo!decvax!harpo!seismo!rlgvax!tom utzoo!decvax!harpo!seismo!rlgvax!tom
Thu Apr 28 16:40:18 AEST 1983


RE: possible undesired optimization of code like:

	while (ADDR->c_reg&BUSY)
		;

I have worked with drivers a great deal in older versions of UNIX and
never had a problem with optimization eliminating the repeated memory
reference.  One reason may be that since UNIX is a timesharing system,
there are very few actual "busy waits" as above (a neat way to hang
a system) but instead:

	while (ADDR->c_reg&BUSY)
		sleep((caddr_t)&x, PRIBIO);

The subroutine call in the loop is enough to turn off any optimization.

But otherwise, in the first example it would seem reasonable to optimize
out the memory reference, to the programmer's displeasure.  This could
become a more widespread problem when shared data spaces cause user
programs to use the same type of code. The "unregister" or "volatile"
declaration mentioned could prove useful (I prefer the second term).

Tom Beres
{we13, mcnc, seismo}!rlgvax!tom



More information about the Comp.lang.c mailing list